summaryrefslogtreecommitdiffstats
path: root/components/url_matcher/url_matcher.cc
diff options
context:
space:
mode:
authormnissler <mnissler@chromium.org>2015-05-29 06:57:41 -0700
committerCommit bot <commit-bot@chromium.org>2015-05-29 13:58:09 +0000
commitd9cdcd8702111079c27787a2d49b48470bc10ae7 (patch)
tree21b8612c0bf4f8b5c805e4a652db400a18d2080b /components/url_matcher/url_matcher.cc
parent673eda698a02bbc74c07b790e52eb5185a693bde (diff)
downloadchromium_src-d9cdcd8702111079c27787a2d49b48470bc10ae7.zip
chromium_src-d9cdcd8702111079c27787a2d49b48470bc10ae7.tar.gz
chromium_src-d9cdcd8702111079c27787a2d49b48470bc10ae7.tar.bz2
url_matcher: Treat FQDN hosts as if they were relative.
This changes URLMatcher to not make a difference between fully-qualified and relative URLs. Patterns that specify fully-qualified host names now also match the corresponding relative host name in URLs and fully-qualified host names in URLs now match patterns that use relative host names. BUG=chromium:493142 TEST=Added unit and browser test coverage. Review URL: https://codereview.chromium.org/1167483002 Cr-Commit-Position: refs/heads/master@{#331963}
Diffstat (limited to 'components/url_matcher/url_matcher.cc')
-rw-r--r--components/url_matcher/url_matcher.cc27
1 files changed, 20 insertions, 7 deletions
diff --git a/components/url_matcher/url_matcher.cc b/components/url_matcher/url_matcher.cc
index 3798f7e..5cdf4a42 100644
--- a/components/url_matcher/url_matcher.cc
+++ b/components/url_matcher/url_matcher.cc
@@ -277,13 +277,13 @@ std::string URLMatcherConditionFactory::CanonicalizeURLForComponentSearches(
URLMatcherCondition URLMatcherConditionFactory::CreateHostPrefixCondition(
const std::string& prefix) {
return CreateCondition(URLMatcherCondition::HOST_PREFIX,
- kBeginningOfURL + CanonicalizeHostname(prefix));
+ kBeginningOfURL + CanonicalizeHostPrefix(prefix));
}
URLMatcherCondition URLMatcherConditionFactory::CreateHostSuffixCondition(
const std::string& suffix) {
return CreateCondition(URLMatcherCondition::HOST_SUFFIX,
- suffix + kEndOfDomain);
+ CanonicalizeHostSuffix(suffix) + kEndOfDomain);
}
URLMatcherCondition URLMatcherConditionFactory::CreateHostContainsCondition(
@@ -365,7 +365,7 @@ URLMatcherCondition
const std::string& host_suffix,
const std::string& path_prefix) {
return CreateCondition(URLMatcherCondition::HOST_SUFFIX_PATH_PREFIX,
- host_suffix + kEndOfDomain + path_prefix);
+ CanonicalizeHostSuffix(host_suffix) + kEndOfDomain + path_prefix);
}
URLMatcherCondition
@@ -521,12 +521,25 @@ URLMatcherCondition URLMatcherConditionFactory::CreateCondition(
}
}
+std::string URLMatcherConditionFactory::CanonicalizeHostSuffix(
+ const std::string& suffix) const {
+ if (!suffix.empty() && suffix[suffix.size() - 1] == '.')
+ return suffix;
+ else
+ return suffix + ".";
+}
+
+std::string URLMatcherConditionFactory::CanonicalizeHostPrefix(
+ const std::string& prefix) const {
+ if (!prefix.empty() && prefix[0] == '.')
+ return prefix;
+ else
+ return "." + prefix;
+}
+
std::string URLMatcherConditionFactory::CanonicalizeHostname(
const std::string& hostname) const {
- if (!hostname.empty() && hostname[0] == '.')
- return hostname;
- else
- return "." + hostname;
+ return CanonicalizeHostPrefix(CanonicalizeHostSuffix(hostname));
}
// This function prepares the query string by replacing query separator with a