Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(352)

Unified Diff: net/base/net_util.cc

Issue 340070: Allow trailing dots on hostnames.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/net_util.h ('k') | net/base/net_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/net_util.cc
===================================================================
--- net/base/net_util.cc (revision 30723)
+++ net/base/net_util.cc (working copy)
@@ -965,27 +965,22 @@
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 @@
}
}
- return state == IN_COMPONENT_STARTED_ALPHA;
+ return most_recent_component_started_alpha;
}
std::string GetDirectoryListingEntry(const string16& name,
« no previous file with comments | « net/base/net_util.h ('k') | net/base/net_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698