diff options
Diffstat (limited to 'chrome/browser/autocomplete')
-rw-r--r-- | chrome/browser/autocomplete/autocomplete.cc | 28 | ||||
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_unittest.cc | 2 |
2 files changed, 13 insertions, 17 deletions
diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc index 4c94637..7678fc7 100644 --- a/chrome/browser/autocomplete/autocomplete.cc +++ b/chrome/browser/autocomplete/autocomplete.cc @@ -164,7 +164,7 @@ AutocompleteInput::Type AutocompleteInput::Parse( const size_t registry_length = net::RegistryControlledDomainService::GetRegistryLength(host, false); if (registry_length == std::wstring::npos) - return QUERY; // It's not clear to me that we can reach this... + return QUERY; // Could be a broken IP address, etc. // A space in the "host" means this is a query. (Technically, IE and GURL // allow hostnames with spaces for wierd intranet machines, but it's supposed @@ -180,27 +180,21 @@ AutocompleteInput::Type AutocompleteInput::Parse( return URL; // See if the host is an IP address. - bool is_ip_address; - const std::string canon_host(net::CanonicalizeHost(host, &is_ip_address)); - if (is_ip_address) { - // If the user typed a valid IPv6 address, treat it as a URL. - if (canon_host[0] == '[') - return URL; - + url_canon::CanonHostInfo host_info; + net::CanonicalizeHost(host, &host_info); + if (host_info.family == url_canon::CanonHostInfo::IPV4) { // If the user originally typed a host that looks like an IP address (a // dotted quad), they probably want to open it. If the original input was // something else (like a single number), they probably wanted to search for // it. This is true even if the URL appears to have a path: "1.2/45" is // more likely a search (for the answer to a math problem) than a URL. - url_parse::Component components[4]; - const bool found_ipv4 = - url_canon::FindIPv4Components(WideToUTF8(text).c_str(), - parts->host, components); - DCHECK(found_ipv4); - for (size_t i = 0; i < arraysize(components); ++i) { - if (!components[i].is_nonempty()) - return desired_tld.empty() ? UNKNOWN : REQUESTED_URL; - } + if (host_info.num_ipv4_components == 4) + return URL; + return desired_tld.empty() ? UNKNOWN : REQUESTED_URL; + } + + if (host_info.family == url_canon::CanonHostInfo::IPV6) { + // If the user typed a valid bracketed IPv6 address, treat it as a URL. return URL; } diff --git a/chrome/browser/autocomplete/autocomplete_unittest.cc b/chrome/browser/autocomplete/autocomplete_unittest.cc index 500d79d3..5115e2f 100644 --- a/chrome/browser/autocomplete/autocomplete_unittest.cc +++ b/chrome/browser/autocomplete/autocomplete_unittest.cc @@ -239,6 +239,8 @@ TEST(AutocompleteTest, InputType) { { L"\u6d4b\u8bd5", AutocompleteInput::UNKNOWN }, { L"[2001:]", AutocompleteInput::QUERY }, // Not a valid IP { L"[2001:dB8::1]", AutocompleteInput::URL }, + { L"192.168.0.256", AutocompleteInput::QUERY }, // Invalid IPv4 literal. + { L"[foo.com]", AutocompleteInput::QUERY }, // Invalid IPv6 literal. }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) { |