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/pattern.h" | 9 #include "base/strings/pattern.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 // Host is required. | 230 // Host is required. |
231 if (host_start_pos == host_end_pos) | 231 if (host_start_pos == host_end_pos) |
232 return PARSE_ERROR_EMPTY_HOST; | 232 return PARSE_ERROR_EMPTY_HOST; |
233 | 233 |
234 if (host_end_pos == std::string::npos) | 234 if (host_end_pos == std::string::npos) |
235 return PARSE_ERROR_EMPTY_PATH; | 235 return PARSE_ERROR_EMPTY_PATH; |
236 | 236 |
237 host_ = pattern.substr(host_start_pos, host_end_pos - host_start_pos); | 237 host_ = pattern.substr(host_start_pos, host_end_pos - host_start_pos); |
238 | 238 |
239 // The first component can optionally be '*' to match all subdomains. | 239 // The first component can optionally be '*' to match all subdomains. |
240 std::vector<std::string> host_components; | 240 std::vector<std::string> host_components = base::SplitString( |
241 base::SplitString(host_, '.', &host_components); | 241 host_, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
242 | 242 |
243 // Could be empty if the host only consists of whitespace characters. | 243 // Could be empty if the host only consists of whitespace characters. |
244 if (host_components.empty()) | 244 if (host_components.empty() || |
| 245 (host_components.size() == 1 && host_components[0].empty())) |
245 return PARSE_ERROR_EMPTY_HOST; | 246 return PARSE_ERROR_EMPTY_HOST; |
246 | 247 |
247 if (host_components[0] == "*") { | 248 if (host_components[0] == "*") { |
248 match_subdomains_ = true; | 249 match_subdomains_ = true; |
249 host_components.erase(host_components.begin(), | 250 host_components.erase(host_components.begin(), |
250 host_components.begin() + 1); | 251 host_components.begin() + 1); |
251 } | 252 } |
252 host_ = base::JoinString(host_components, "."); | 253 host_ = base::JoinString(host_components, "."); |
253 | 254 |
254 path_start_pos = host_end_pos; | 255 path_start_pos = host_end_pos; |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 } | 607 } |
607 | 608 |
608 return result; | 609 return result; |
609 } | 610 } |
610 | 611 |
611 // static | 612 // static |
612 const char* URLPattern::GetParseResultString( | 613 const char* URLPattern::GetParseResultString( |
613 URLPattern::ParseResult parse_result) { | 614 URLPattern::ParseResult parse_result) { |
614 return kParseResultMessages[parse_result]; | 615 return kParseResultMessages[parse_result]; |
615 } | 616 } |
OLD | NEW |