OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "extensions/common/url_pattern.h" | 5 #include "extensions/common/url_pattern.h" |
6 | 6 |
7 #include <ostream> | 7 #include <ostream> |
8 | 8 |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 must_keep_these_arrays_in_sync); | 47 must_keep_these_arrays_in_sync); |
48 | 48 |
49 const char kParseSuccess[] = "Success."; | 49 const char kParseSuccess[] = "Success."; |
50 const char kParseErrorMissingSchemeSeparator[] = "Missing scheme separator."; | 50 const char kParseErrorMissingSchemeSeparator[] = "Missing scheme separator."; |
51 const char kParseErrorInvalidScheme[] = "Invalid scheme."; | 51 const char kParseErrorInvalidScheme[] = "Invalid scheme."; |
52 const char kParseErrorWrongSchemeType[] = "Wrong scheme type."; | 52 const char kParseErrorWrongSchemeType[] = "Wrong scheme type."; |
53 const char kParseErrorEmptyHost[] = "Host can not be empty."; | 53 const char kParseErrorEmptyHost[] = "Host can not be empty."; |
54 const char kParseErrorInvalidHostWildcard[] = "Invalid host wildcard."; | 54 const char kParseErrorInvalidHostWildcard[] = "Invalid host wildcard."; |
55 const char kParseErrorEmptyPath[] = "Empty path."; | 55 const char kParseErrorEmptyPath[] = "Empty path."; |
56 const char kParseErrorInvalidPort[] = "Invalid port."; | 56 const char kParseErrorInvalidPort[] = "Invalid port."; |
| 57 const char kParseErrorInvalidHost[] = "Invalid host."; |
57 | 58 |
58 // Message explaining each URLPattern::ParseResult. | 59 // Message explaining each URLPattern::ParseResult. |
59 const char* const kParseResultMessages[] = { | 60 const char* const kParseResultMessages[] = { |
60 kParseSuccess, | 61 kParseSuccess, |
61 kParseErrorMissingSchemeSeparator, | 62 kParseErrorMissingSchemeSeparator, |
62 kParseErrorInvalidScheme, | 63 kParseErrorInvalidScheme, |
63 kParseErrorWrongSchemeType, | 64 kParseErrorWrongSchemeType, |
64 kParseErrorEmptyHost, | 65 kParseErrorEmptyHost, |
65 kParseErrorInvalidHostWildcard, | 66 kParseErrorInvalidHostWildcard, |
66 kParseErrorEmptyPath, | 67 kParseErrorEmptyPath, |
67 kParseErrorInvalidPort, | 68 kParseErrorInvalidPort, |
| 69 kParseErrorInvalidHost, |
68 }; | 70 }; |
69 | 71 |
70 COMPILE_ASSERT(URLPattern::NUM_PARSE_RESULTS == arraysize(kParseResultMessages), | 72 COMPILE_ASSERT(URLPattern::NUM_PARSE_RESULTS == arraysize(kParseResultMessages), |
71 must_add_message_for_each_parse_result); | 73 must_add_message_for_each_parse_result); |
72 | 74 |
73 const char kPathSeparator[] = "/"; | 75 const char kPathSeparator[] = "/"; |
74 | 76 |
75 bool IsStandardScheme(const std::string& scheme) { | 77 bool IsStandardScheme(const std::string& scheme) { |
76 // "*" gets the same treatment as a standard scheme. | 78 // "*" gets the same treatment as a standard scheme. |
77 if (scheme == "*") | 79 if (scheme == "*") |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 return PARSE_ERROR_INVALID_PORT; | 261 return PARSE_ERROR_INVALID_PORT; |
260 host_ = host_.substr(0, port_pos); | 262 host_ = host_.substr(0, port_pos); |
261 } | 263 } |
262 | 264 |
263 // No other '*' can occur in the host, though. This isn't necessary, but is | 265 // No other '*' can occur in the host, though. This isn't necessary, but is |
264 // done as a convenience to developers who might otherwise be confused and | 266 // done as a convenience to developers who might otherwise be confused and |
265 // think '*' works as a glob in the host. | 267 // think '*' works as a glob in the host. |
266 if (host_.find('*') != std::string::npos) | 268 if (host_.find('*') != std::string::npos) |
267 return PARSE_ERROR_INVALID_HOST_WILDCARD; | 269 return PARSE_ERROR_INVALID_HOST_WILDCARD; |
268 | 270 |
| 271 // Null characters are not allowed in hosts. |
| 272 if (host_.find('\0') != std::string::npos) |
| 273 return PARSE_ERROR_INVALID_HOST; |
| 274 |
269 return PARSE_SUCCESS; | 275 return PARSE_SUCCESS; |
270 } | 276 } |
271 | 277 |
272 void URLPattern::SetValidSchemes(int valid_schemes) { | 278 void URLPattern::SetValidSchemes(int valid_schemes) { |
273 spec_.clear(); | 279 spec_.clear(); |
274 valid_schemes_ = valid_schemes; | 280 valid_schemes_ = valid_schemes; |
275 } | 281 } |
276 | 282 |
277 void URLPattern::SetHost(const std::string& host) { | 283 void URLPattern::SetHost(const std::string& host) { |
278 spec_.clear(); | 284 spec_.clear(); |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 } | 599 } |
594 | 600 |
595 return result; | 601 return result; |
596 } | 602 } |
597 | 603 |
598 // static | 604 // static |
599 const char* URLPattern::GetParseResultString( | 605 const char* URLPattern::GetParseResultString( |
600 URLPattern::ParseResult parse_result) { | 606 URLPattern::ParseResult parse_result) { |
601 return kParseResultMessages[parse_result]; | 607 return kParseResultMessages[parse_result]; |
602 } | 608 } |
OLD | NEW |