summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autocomplete
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-22 20:05:59 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-22 20:05:59 +0000
commit7e563816b35dcc102eb69849295b5f6f9d048a63 (patch)
treeb6a833b3b32b58ed8453f1d63682c77d6b158d08 /chrome/browser/autocomplete
parent1679e8667e258a9903a18792894e13a17639e122 (diff)
downloadchromium_src-7e563816b35dcc102eb69849295b5f6f9d048a63.zip
chromium_src-7e563816b35dcc102eb69849295b5f6f9d048a63.tar.gz
chromium_src-7e563816b35dcc102eb69849295b5f6f9d048a63.tar.bz2
Make various types of input work better with ctrl-enter. If we detected that the hostname without adding the TLD was illegal, we'd sometimes fail to allow the TLD to be added.
BUG=38605 TEST=Should be able to hit ctrl-enter on "401k" and "999999999999" to open them with www. and .com attached. Review URL: http://codereview.chromium.org/1088004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42246 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete')
-rw-r--r--chrome/browser/autocomplete/autocomplete.cc19
-rw-r--r--chrome/browser/autocomplete/autocomplete_unittest.cc16
2 files changed, 33 insertions, 2 deletions
diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc
index eca1038..2167ea2 100644
--- a/chrome/browser/autocomplete/autocomplete.cc
+++ b/chrome/browser/autocomplete/autocomplete.cc
@@ -172,8 +172,22 @@ AutocompleteInput::Type AutocompleteInput::Parse(
const std::wstring host(text.substr(parts->host.begin, parts->host.len));
const size_t registry_length =
net::RegistryControlledDomainService::GetRegistryLength(host, false);
- if (registry_length == std::wstring::npos)
+ if (registry_length == std::wstring::npos) {
+ // Try to append the desired_tld.
+ if (!desired_tld.empty()) {
+ std::wstring host_with_tld(host);
+ if (host[host.length() - 1] != '.')
+ host_with_tld += '.';
+ host_with_tld += desired_tld;
+ if (net::RegistryControlledDomainService::GetRegistryLength(
+ host_with_tld, false) != std::wstring::npos)
+ return REQUESTED_URL; // Something like "99999999999" that looks like a
+ // bad IP address, but becomes valid on attaching
+ // a TLD.
+ }
return QUERY; // Could be a broken IP address, etc.
+ }
+
// See if the hostname is valid. While IE and GURL allow hostnames to contain
// many other characters (perhaps for weird intranet machines), it's extremely
@@ -182,7 +196,8 @@ AutocompleteInput::Type AutocompleteInput::Parse(
url_canon::CanonHostInfo host_info;
const std::string canonicalized_host(net::CanonicalizeHost(host, &host_info));
if ((host_info.family == url_canon::CanonHostInfo::NEUTRAL) &&
- !net::IsCanonicalizedHostCompliant(canonicalized_host)) {
+ !net::IsCanonicalizedHostCompliant(canonicalized_host,
+ WideToUTF8(desired_tld))) {
// Invalid hostname. There are several possible cases:
// * Our checker is too strict and the user pasted in a real-world URL
// that's "invalid" but resolves. To catch these, we return UNKNOWN when
diff --git a/chrome/browser/autocomplete/autocomplete_unittest.cc b/chrome/browser/autocomplete/autocomplete_unittest.cc
index 2507310..8042724 100644
--- a/chrome/browser/autocomplete/autocomplete_unittest.cc
+++ b/chrome/browser/autocomplete/autocomplete_unittest.cc
@@ -280,6 +280,22 @@ TEST(AutocompleteTest, InputType) {
}
}
+TEST(AutocompleteTest, InputTypeWithDesiredTLD) {
+ struct test_data {
+ const wchar_t* input;
+ const AutocompleteInput::Type type;
+ } input_cases[] = {
+ { L"401k", AutocompleteInput::REQUESTED_URL },
+ { L"999999999999999", AutocompleteInput::REQUESTED_URL },
+ };
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) {
+ AutocompleteInput input(input_cases[i].input, L"com", true, false, false);
+ EXPECT_EQ(input_cases[i].type, input.type()) << "Input: " <<
+ input_cases[i].input;
+ }
+}
+
// This tests for a regression where certain input in the omnibox caused us to
// crash. As long as the test completes without crashing, we're fine.
TEST(AutocompleteTest, InputCrash) {