summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autocomplete
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-23 22:52:42 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-23 22:52:42 +0000
commit01dbd931735c7b7497b7b83664462512f272bf58 (patch)
tree39eaf9d56354fa8b45aadedd6faaf03aec000b98 /chrome/browser/autocomplete
parent99224582c3e56f3cb354f633baf06caa5b98e751 (diff)
downloadchromium_src-01dbd931735c7b7497b7b83664462512f272bf58.zip
chromium_src-01dbd931735c7b7497b7b83664462512f272bf58.tar.gz
chromium_src-01dbd931735c7b7497b7b83664462512f272bf58.tar.bz2
Original patch by pmarks@google.com (see http://codereview.chromium.org/113944)
- Pull in googleurl r107, which includes the new CanonicalizeHostVerbose() function: http://code.google.com/p/google-url/source/detail?r=107 - Atomically update Chromium to make use of this new function. This allows us to extract better information about IP addresses using fewer, and cleaner, calls to googleurl. - Also, change a call to CanonicalizeIPAddress() to stay compatible with r107. The upshot of all this is, Chrome will no longer try to connect to IPv4 addresses with overflow "http://192.168.0.257", or hostnames surrounded by square brackets "http://[google.com]" BUG=none TEST={unit_tests,googleurl_unittests,net_unittests} Review URL: http://codereview.chromium.org/146053 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19076 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete')
-rw-r--r--chrome/browser/autocomplete/autocomplete.cc28
-rw-r--r--chrome/browser/autocomplete/autocomplete_unittest.cc2
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) {