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

Unified Diff: net/base/net_util.cc

Issue 271116: Classify more types of input as queries.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 2 months 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
Index: net/base/net_util.cc
===================================================================
--- net/base/net_util.cc (revision 29226)
+++ net/base/net_util.cc (working copy)
@@ -939,6 +939,54 @@
return result;
}
+inline bool IsHostCharAlpha(char c) {
+ // We can just check lowercase because uppercase characters have already been
+ // normalized.
+ return (c >= 'a') && (c <= 'z');
+}
+
+inline bool IsHostCharDigit(char c) {
+ return (c >= '0') && (c <= '9');
+}
+
+bool IsCanonicalizedHostRFC1738Compliant(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 last_char_was_hyphen = 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
+ return false;
+ } else {
+ if (c == '.') {
+ if (last_char_was_hyphen)
+ return false;
+ state = NOT_IN_COMPONENT;
+ } else if (IsHostCharAlpha(c) || IsHostCharDigit(c)) {
+ last_char_was_hyphen = false;
+ } else if (c == '-') {
+ last_char_was_hyphen = true;
+ } else {
+ return false;
+ }
+ }
+ }
+
+ return state == IN_COMPONENT_STARTED_ALPHA;
+}
+
std::string GetDirectoryListingEntry(const string16& name,
const std::string& raw_bytes,
bool is_dir,

Powered by Google App Engine
This is Rietveld 408576698