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/url_util.h" | 5 #include "url/url_util.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
609 void EncodeURIComponent(const char* input, int length, CanonOutput* output) { | 609 void EncodeURIComponent(const char* input, int length, CanonOutput* output) { |
610 for (int i = 0; i < length; ++i) { | 610 for (int i = 0; i < length; ++i) { |
611 unsigned char c = static_cast<unsigned char>(input[i]); | 611 unsigned char c = static_cast<unsigned char>(input[i]); |
612 if (IsComponentChar(c)) | 612 if (IsComponentChar(c)) |
613 output->push_back(c); | 613 output->push_back(c); |
614 else | 614 else |
615 AppendEscapedChar(c, output); | 615 AppendEscapedChar(c, output); |
616 } | 616 } |
617 } | 617 } |
618 | 618 |
619 bool DomainIs(base::StringPiece canonicalized_host, | |
620 base::StringPiece lower_ascii_domain) { | |
621 DCHECK(!canonicalized_host.empty()); | |
engedy
2016/08/26 16:48:14
I think it would be safer if this shared stuff did
pkalinnikov
2016/08/29 09:53:00
Done.
| |
622 DCHECK(!lower_ascii_domain.empty()); | |
623 | |
624 // If the host name ends with a dot but the input domain doesn't, then we | |
625 // ignore the dot in the host name. | |
626 size_t host_len = canonicalized_host.length(); | |
627 if (canonicalized_host.back() == '.' && lower_ascii_domain.back() != '.') | |
628 --host_len; | |
629 | |
630 if (host_len < lower_ascii_domain.length()) | |
631 return false; | |
632 | |
633 // |host_first_pos| is the start of the compared part of the host name, not | |
634 // start of the whole host name. | |
635 const char* host_first_pos = | |
636 canonicalized_host.data() + host_len - lower_ascii_domain.length(); | |
637 | |
638 if (!base::LowerCaseEqualsASCII( | |
639 base::StringPiece(host_first_pos, lower_ascii_domain.length()), | |
640 lower_ascii_domain)) { | |
641 return false; | |
642 } | |
643 | |
644 // Make sure there aren't extra characters in host before the compared part; | |
645 // if the host name is longer than the input domain name, then the character | |
646 // immediately before the compared part should be a dot. For example, | |
647 // www.google.com has domain "google.com", but www.iamnotgoogle.com does not. | |
648 if (lower_ascii_domain[0] != '.' && host_len > lower_ascii_domain.length() && | |
649 *(host_first_pos - 1) != '.') { | |
650 return false; | |
651 } | |
652 | |
653 return true; | |
654 } | |
655 | |
619 bool CompareSchemeComponent(const char* spec, | 656 bool CompareSchemeComponent(const char* spec, |
620 const Component& component, | 657 const Component& component, |
621 const char* compare_to) { | 658 const char* compare_to) { |
622 return DoCompareSchemeComponent(spec, component, compare_to); | 659 return DoCompareSchemeComponent(spec, component, compare_to); |
623 } | 660 } |
624 | 661 |
625 bool CompareSchemeComponent(const base::char16* spec, | 662 bool CompareSchemeComponent(const base::char16* spec, |
626 const Component& component, | 663 const Component& component, |
627 const char* compare_to) { | 664 const char* compare_to) { |
628 return DoCompareSchemeComponent(spec, component, compare_to); | 665 return DoCompareSchemeComponent(spec, component, compare_to); |
629 } | 666 } |
630 | 667 |
631 } // namespace url | 668 } // namespace url |
OLD | NEW |