| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "url/gurl.h" | 5 #include "url/gurl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <ostream> | 10 #include <ostream> |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 #endif // WIN32 | 491 #endif // WIN32 |
| 492 | 492 |
| 493 bool GURL::DomainIs(base::StringPiece lower_ascii_domain) const { | 493 bool GURL::DomainIs(base::StringPiece lower_ascii_domain) const { |
| 494 if (!is_valid_ || lower_ascii_domain.empty()) | 494 if (!is_valid_ || lower_ascii_domain.empty()) |
| 495 return false; | 495 return false; |
| 496 | 496 |
| 497 // FileSystem URLs have empty parsed_.host, so check this first. | 497 // FileSystem URLs have empty parsed_.host, so check this first. |
| 498 if (SchemeIsFileSystem() && inner_url_) | 498 if (SchemeIsFileSystem() && inner_url_) |
| 499 return inner_url_->DomainIs(lower_ascii_domain); | 499 return inner_url_->DomainIs(lower_ascii_domain); |
| 500 | 500 |
| 501 if (!parsed_.host.is_nonempty()) | 501 return parsed_.host.is_nonempty() && |
| 502 return false; | 502 url::DomainIs(host_piece(), lower_ascii_domain); |
| 503 | |
| 504 // If the host name ends with a dot but the input domain doesn't, | |
| 505 // then we ignore the dot in the host name. | |
| 506 const char* host_last_pos = spec_.data() + parsed_.host.end() - 1; | |
| 507 int host_len = parsed_.host.len; | |
| 508 int domain_len = lower_ascii_domain.length(); | |
| 509 if ('.' == *host_last_pos && '.' != lower_ascii_domain[domain_len - 1]) { | |
| 510 host_last_pos--; | |
| 511 host_len--; | |
| 512 } | |
| 513 | |
| 514 if (host_len < domain_len) | |
| 515 return false; | |
| 516 | |
| 517 // |host_first_pos| is the start of the compared part of the host name, not | |
| 518 // start of the whole host name. | |
| 519 const char* host_first_pos = spec_.data() + parsed_.host.begin + | |
| 520 host_len - domain_len; | |
| 521 | |
| 522 if (!base::LowerCaseEqualsASCII( | |
| 523 base::StringPiece(host_first_pos, domain_len), lower_ascii_domain)) | |
| 524 return false; | |
| 525 | |
| 526 // Make sure there aren't extra characters in host before the compared part; | |
| 527 // if the host name is longer than the input domain name, then the character | |
| 528 // immediately before the compared part should be a dot. For example, | |
| 529 // www.google.com has domain "google.com", but www.iamnotgoogle.com does not. | |
| 530 if ('.' != lower_ascii_domain[0] && host_len > domain_len && | |
| 531 '.' != *(host_first_pos - 1)) | |
| 532 return false; | |
| 533 | |
| 534 return true; | |
| 535 } | 503 } |
| 536 | 504 |
| 537 void GURL::Swap(GURL* other) { | 505 void GURL::Swap(GURL* other) { |
| 538 spec_.swap(other->spec_); | 506 spec_.swap(other->spec_); |
| 539 std::swap(is_valid_, other->is_valid_); | 507 std::swap(is_valid_, other->is_valid_); |
| 540 std::swap(parsed_, other->parsed_); | 508 std::swap(parsed_, other->parsed_); |
| 541 inner_url_.swap(other->inner_url_); | 509 inner_url_.swap(other->inner_url_); |
| 542 } | 510 } |
| 543 | 511 |
| 544 std::ostream& operator<<(std::ostream& out, const GURL& url) { | 512 std::ostream& operator<<(std::ostream& out, const GURL& url) { |
| 545 return out << url.possibly_invalid_spec(); | 513 return out << url.possibly_invalid_spec(); |
| 546 } | 514 } |
| OLD | NEW |