diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-03 18:17:26 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-03 18:17:26 +0000 |
commit | d120c37264be4ed06b52e64acd390939ebe6e13e (patch) | |
tree | 578eca4ce2fd5cf9602a568f457f2ad4e1fb4dc9 | |
parent | 20824e8b140ef43bac73e0fa70c55257333b271f (diff) | |
download | chromium_src-d120c37264be4ed06b52e64acd390939ebe6e13e.zip chromium_src-d120c37264be4ed06b52e64acd390939ebe6e13e.tar.gz chromium_src-d120c37264be4ed06b52e64acd390939ebe6e13e.tar.bz2 |
Allow trailing dots on hostnames.
BUG=25962
TEST=Type in "google.com." and verify you can navigate.
Review URL: http://codereview.chromium.org/340070
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30828 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | net/base/net_util.cc | 21 | ||||
-rw-r--r-- | net/base/net_util.h | 1 | ||||
-rw-r--r-- | net/base/net_util_unittest.cc | 4 |
3 files changed, 12 insertions, 14 deletions
diff --git a/net/base/net_util.cc b/net/base/net_util.cc index 5c91a68..9715aa0e 100644 --- a/net/base/net_util.cc +++ b/net/base/net_util.cc @@ -965,27 +965,22 @@ bool IsCanonicalizedHostCompliant(const std::string& host) { if (host.empty()) return false; - enum State { - NOT_IN_COMPONENT, - IN_COMPONENT_STARTED_DIGIT, - IN_COMPONENT_STARTED_ALPHA - } state = NOT_IN_COMPONENT; + bool in_component = false; + bool most_recent_component_started_alpha = false; bool last_char_was_hyphen_or_underscore = false; for (std::string::const_iterator i(host.begin()); i != host.end(); ++i) { const char c = *i; - if (state == NOT_IN_COMPONENT) { - if (IsHostCharDigit(c)) - state = IN_COMPONENT_STARTED_DIGIT; - else if (IsHostCharAlpha(c)) - state = IN_COMPONENT_STARTED_ALPHA; - else + if (!in_component) { + most_recent_component_started_alpha = IsHostCharAlpha(c); + if (!most_recent_component_started_alpha && !IsHostCharDigit(c)) return false; + in_component = true; } else { if (c == '.') { if (last_char_was_hyphen_or_underscore) return false; - state = NOT_IN_COMPONENT; + in_component = false; } else if (IsHostCharAlpha(c) || IsHostCharDigit(c)) { last_char_was_hyphen_or_underscore = false; } else if ((c == '-') || (c == '_')) { @@ -996,7 +991,7 @@ bool IsCanonicalizedHostCompliant(const std::string& host) { } } - return state == IN_COMPONENT_STARTED_ALPHA; + return most_recent_component_started_alpha; } std::string GetDirectoryListingEntry(const string16& name, diff --git a/net/base/net_util.h b/net/base/net_util.h index 0d78598..9ef4933 100644 --- a/net/base/net_util.h +++ b/net/base/net_util.h @@ -165,6 +165,7 @@ std::string CanonicalizeHost(const std::wstring& host, // * Each component begins and ends with an alphanumeric character // * Each component contains only alphanumeric characters and '-' or '_' // * The last component does not begin with a digit +// * Optional trailing dot after last component (means "treat as FQDN") // // NOTE: You should only pass in hosts that have been returned from // CanonicalizeHost(), or you may not get accurate results. diff --git a/net/base/net_util_unittest.cc b/net/base/net_util_unittest.cc index 23376d5..1445e43 100644 --- a/net/base/net_util_unittest.cc +++ b/net/base/net_util_unittest.cc @@ -821,7 +821,7 @@ TEST(NetUtilTest, CompliantHost) { {"a", true}, {"-", false}, {".", false}, - {"a.", false}, + {"a.", true}, {"a.a", true}, {"9.a", true}, {"a.9", false}, @@ -834,6 +834,8 @@ TEST(NetUtilTest, CompliantHost) { {"a.b.c.d.e", true}, {"1.2.3.4.e", true}, {"a.b.c.d.5", false}, + {"1.2.3.4.e.", true}, + {"a.b.c.d.5.", false}, }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(compliant_host_cases); ++i) { |