Chromium Code Reviews| Index: chrome/browser/autocomplete/autocomplete.cc |
| =================================================================== |
| --- chrome/browser/autocomplete/autocomplete.cc (revision 29226) |
| +++ chrome/browser/autocomplete/autocomplete.cc (working copy) |
| @@ -168,22 +168,33 @@ |
| if (registry_length == std::wstring::npos) |
| 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 |
| - // to be illegal and I'm not worried about users trying to type these in.) |
| - if (host.find(' ') != std::wstring::npos) |
| + // See if the hostname is valid per RFC 1738. While IE and GURL allow |
| + // hostnames to contain many other characters (perhaps for weird intranet |
| + // machines), it's extremely unlikely that a user would be trying to type |
| + // those in for anything other than a search query. |
| + url_canon::CanonHostInfo host_info; |
| + const std::string canonicalized_host(net::CanonicalizeHost(host, &host_info)); |
| + if ((host_info.family == url_canon::CanonHostInfo::NEUTRAL) && |
| + !net::IsCanonicalizedHostRFC1738Compliant(canonicalized_host)) |
| return QUERY; |
| - // Presence of a password/port mean this is almost certainly a URL. We don't |
| - // treat usernames (without passwords) as indicating a URL, because this could |
| - // be an email address like "user@mail.com" which is more likely a search than |
| - // an HTTP auth login attempt. |
| - if (parts->password.is_nonempty() || parts->port.is_nonempty()) |
| + // Presence of a port means this is likely a URL, if the port is really a port |
| + // number. If it's just garbage after a colon, this is a query. |
| + if (parts->port.is_nonempty()) { |
| + int port; |
| + return (StringToInt(WideToUTF16( |
| + text.substr(parts->port.begin, parts->port.len)), &port) && |
| + (port >= 0) && (port <= 65535)) ? URL : QUERY; |
|
Peter Kasting
2009/10/16 01:54:10
I know you will hate this, but it doesn't really l
|
| + } |
| + |
| + // Presence of a password means this is likely a URL. We don't treat |
| + // usernames (without passwords) as indicating a URL, because this could be an |
| + // email address like "user@mail.com" which is more likely a search than an |
| + // HTTP auth login attempt. |
| + if (parts->password.is_nonempty()) |
| return URL; |
| // See if the host is an IP address. |
| - 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 |
| @@ -194,11 +205,8 @@ |
| 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. |
| + if (host_info.family == url_canon::CanonHostInfo::IPV6) |
| return URL; |
| - } |
| // The host doesn't look like a number, so see if the user's given us a path. |
| if (parts->path.is_nonempty()) { |