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

Side by Side 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 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 947 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 IsCanonicalizedHostCompliant(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 bool in_component = false;
969 NOT_IN_COMPONENT, 969 bool most_recent_component_started_alpha = false;
970 IN_COMPONENT_STARTED_DIGIT,
971 IN_COMPONENT_STARTED_ALPHA
972 } state = NOT_IN_COMPONENT;
973 bool last_char_was_hyphen_or_underscore = false; 970 bool last_char_was_hyphen_or_underscore = false;
974 971
975 for (std::string::const_iterator i(host.begin()); i != host.end(); ++i) { 972 for (std::string::const_iterator i(host.begin()); i != host.end(); ++i) {
976 const char c = *i; 973 const char c = *i;
977 if (state == NOT_IN_COMPONENT) { 974 if (!in_component) {
978 if (IsHostCharDigit(c)) 975 most_recent_component_started_alpha = IsHostCharAlpha(c);
979 state = IN_COMPONENT_STARTED_DIGIT; 976 if (!most_recent_component_started_alpha && !IsHostCharDigit(c))
980 else if (IsHostCharAlpha(c))
981 state = IN_COMPONENT_STARTED_ALPHA;
982 else
983 return false; 977 return false;
978 in_component = true;
984 } else { 979 } else {
985 if (c == '.') { 980 if (c == '.') {
986 if (last_char_was_hyphen_or_underscore) 981 if (last_char_was_hyphen_or_underscore)
987 return false; 982 return false;
988 state = NOT_IN_COMPONENT; 983 in_component = false;
989 } else if (IsHostCharAlpha(c) || IsHostCharDigit(c)) { 984 } else if (IsHostCharAlpha(c) || IsHostCharDigit(c)) {
990 last_char_was_hyphen_or_underscore = false; 985 last_char_was_hyphen_or_underscore = false;
991 } else if ((c == '-') || (c == '_')) { 986 } else if ((c == '-') || (c == '_')) {
992 last_char_was_hyphen_or_underscore = true; 987 last_char_was_hyphen_or_underscore = true;
993 } else { 988 } else {
994 return false; 989 return false;
995 } 990 }
996 } 991 }
997 } 992 }
998 993
999 return state == IN_COMPONENT_STARTED_ALPHA; 994 return most_recent_component_started_alpha;
1000 } 995 }
1001 996
1002 std::string GetDirectoryListingEntry(const string16& name, 997 std::string GetDirectoryListingEntry(const string16& name,
1003 const std::string& raw_bytes, 998 const std::string& raw_bytes,
1004 bool is_dir, 999 bool is_dir,
1005 int64 size, 1000 int64 size,
1006 Time modified) { 1001 Time modified) {
1007 std::string result; 1002 std::string result;
1008 result.append("<script>addRow("); 1003 result.append("<script>addRow(");
1009 base::JsonDoubleQuote(name, true, &result); 1004 base::JsonDoubleQuote(name, true, &result);
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
1451 if (length > 0) 1446 if (length > 0)
1452 ports.insert(StringToInt(WideToASCII( 1447 ports.insert(StringToInt(WideToASCII(
1453 allowed_ports.substr(last, length)))); 1448 allowed_ports.substr(last, length))));
1454 last = i + 1; 1449 last = i + 1;
1455 } 1450 }
1456 } 1451 }
1457 explicitly_allowed_ports = ports; 1452 explicitly_allowed_ports = ports;
1458 } 1453 }
1459 1454
1460 } // namespace net 1455 } // 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