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

Side by Side Diff: net/base/net_util.cc

Issue 339017: Loosen RFC 1738 compliance check to allow underscores where we already allowe... (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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/net_util.h ('k') | net/base/net_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/base/net_util.h" 5 #include "net/base/net_util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <unicode/ucnv.h> 9 #include <unicode/ucnv.h>
10 #include <unicode/uidna.h> 10 #include <unicode/uidna.h>
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 inline bool IsHostCharAlpha(char c) { 954 inline bool IsHostCharAlpha(char c) {
955 // We can just check lowercase because uppercase characters have already been 955 // We can just check lowercase because uppercase characters have already been
956 // normalized. 956 // normalized.
957 return (c >= 'a') && (c <= 'z'); 957 return (c >= 'a') && (c <= 'z');
958 } 958 }
959 959
960 inline bool IsHostCharDigit(char c) { 960 inline bool IsHostCharDigit(char c) {
961 return (c >= '0') && (c <= '9'); 961 return (c >= '0') && (c <= '9');
962 } 962 }
963 963
964 bool IsCanonicalizedHostRFC1738Compliant(const std::string& host) { 964 bool IsCanonicalizedHostCompliant(const std::string& host) {
965 if (host.empty()) 965 if (host.empty())
966 return false; 966 return false;
967 967
968 enum State { 968 enum State {
969 NOT_IN_COMPONENT, 969 NOT_IN_COMPONENT,
970 IN_COMPONENT_STARTED_DIGIT, 970 IN_COMPONENT_STARTED_DIGIT,
971 IN_COMPONENT_STARTED_ALPHA 971 IN_COMPONENT_STARTED_ALPHA
972 } state = NOT_IN_COMPONENT; 972 } state = NOT_IN_COMPONENT;
973 bool last_char_was_hyphen = false; 973 bool last_char_was_hyphen_or_underscore = false;
974 974
975 for (std::string::const_iterator i(host.begin()); i != host.end(); ++i) { 975 for (std::string::const_iterator i(host.begin()); i != host.end(); ++i) {
976 const char c = *i; 976 const char c = *i;
977 if (state == NOT_IN_COMPONENT) { 977 if (state == NOT_IN_COMPONENT) {
978 if (IsHostCharDigit(c)) 978 if (IsHostCharDigit(c))
979 state = IN_COMPONENT_STARTED_DIGIT; 979 state = IN_COMPONENT_STARTED_DIGIT;
980 else if (IsHostCharAlpha(c)) 980 else if (IsHostCharAlpha(c))
981 state = IN_COMPONENT_STARTED_ALPHA; 981 state = IN_COMPONENT_STARTED_ALPHA;
982 else 982 else
983 return false; 983 return false;
984 } else { 984 } else {
985 if (c == '.') { 985 if (c == '.') {
986 if (last_char_was_hyphen) 986 if (last_char_was_hyphen_or_underscore)
987 return false; 987 return false;
988 state = NOT_IN_COMPONENT; 988 state = NOT_IN_COMPONENT;
989 } else if (IsHostCharAlpha(c) || IsHostCharDigit(c)) { 989 } else if (IsHostCharAlpha(c) || IsHostCharDigit(c)) {
990 last_char_was_hyphen = false; 990 last_char_was_hyphen_or_underscore = false;
991 } else if (c == '-') { 991 } else if ((c == '-') || (c == '_')) {
992 last_char_was_hyphen = true; 992 last_char_was_hyphen_or_underscore = true;
993 } else { 993 } else {
994 return false; 994 return false;
995 } 995 }
996 } 996 }
997 } 997 }
998 998
999 return state == IN_COMPONENT_STARTED_ALPHA; 999 return state == IN_COMPONENT_STARTED_ALPHA;
1000 } 1000 }
1001 1001
1002 std::string GetDirectoryListingEntry(const string16& name, 1002 std::string GetDirectoryListingEntry(const string16& name,
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
1451 if (length > 0) 1451 if (length > 0)
1452 ports.insert(StringToInt(WideToASCII( 1452 ports.insert(StringToInt(WideToASCII(
1453 allowed_ports.substr(last, length)))); 1453 allowed_ports.substr(last, length))));
1454 last = i + 1; 1454 last = i + 1;
1455 } 1455 }
1456 } 1456 }
1457 explicitly_allowed_ports = ports; 1457 explicitly_allowed_ports = ports;
1458 } 1458 }
1459 1459
1460 } // namespace net 1460 } // namespace net
OLDNEW
« 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