URLPatternIndex: Allow separator placeholder to match the end of url.
This CL modifies the URLPatternIndex matching algorithm to ensure that the
separator placeholder (^) also matches the end of the text, thus fixing an
existing TODO.
BUG=772260
Change-Id: If6917c1ea4c7a037765ca421075bf298f64c5ceb
Reviewed-on: https://chromium-review.googlesource.com/c/1476814
Commit-Queue: Karan Bhatia <[email protected]>
Reviewed-by: Istiaque Ahmed <[email protected]>
Reviewed-by: Charlie Harrison <[email protected]>
Cr-Commit-Position: refs/heads/master@{#633869}
diff --git a/components/url_pattern_index/url_pattern_unittest.cc b/components/url_pattern_index/url_pattern_unittest.cc
index d067d12..950c907 100644
--- a/components/url_pattern_index/url_pattern_unittest.cc
+++ b/components/url_pattern_index/url_pattern_unittest.cc
@@ -90,7 +90,9 @@
{{"^^a^^"}, "http://ex.com/?a=/", true},
{{"^^a^^"}, "http://ex.com/?a=/&b=0", true},
- {{"^^a^^"}, "http://ex.com/?a=", false},
+ {{"^^a^^"}, "http://ex.com/?a=x", false},
+ // The last ^ matches the end of the url.
+ {{"^^a^^"}, "http://ex.com/?a=", true},
{{"ex.com^path^*k=v^"}, "http://ex.com/path/?k1=v1&ak=v&kk=vv", true},
{{"ex.com^path^*k=v^"}, "http://ex.com/p/path/?k1=v1&ak=v&kk=vv", false},
@@ -152,6 +154,38 @@
{{"abc*def^", proto::URL_PATTERN_TYPE_WILDCARDED, kDonotMatchCase},
"http://a.com/abcxAdef/vo",
true},
+ {{"abc^", kAnchorNone, kAnchorNone}, "https://xyz.com/abc/123", true},
+ {{"abc^", kAnchorNone, kAnchorNone}, "https://xyz.com/abc", true},
+ {{"abc^", kAnchorNone, kAnchorNone}, "https://abc.com", false},
+ {{"abc^", kAnchorNone, kBoundary}, "https://xyz.com/abc/", true},
+ {{"abc^", kAnchorNone, kBoundary}, "https://xyz.com/abc", true},
+ {{"abc^", kAnchorNone, kBoundary}, "https://xyz.com/abc/123", false},
+ {{"http://abc.com/x^", kBoundary, kAnchorNone}, "http://abc.com/x", true},
+ {{"http://abc.com/x^", kBoundary, kAnchorNone},
+ "http://abc.com/x/",
+ true},
+ {{"http://abc.com/x^", kBoundary, kAnchorNone},
+ "http://abc.com/x/123",
+ true},
+ {{"http://abc.com/x^", kBoundary, kBoundary}, "http://abc.com/x", true},
+ {{"http://abc.com/x^", kBoundary, kBoundary}, "http://abc.com/x/", true},
+ {{"http://abc.com/x^", kBoundary, kBoundary},
+ "http://abc.com/x/123",
+ false},
+ {{"abc.com^", kSubdomain, kAnchorNone}, "http://xyz.abc.com/123", true},
+ {{"abc.com^", kSubdomain, kAnchorNone}, "http://xyz.abc.com", true},
+ {{"abc.com^", kSubdomain, kAnchorNone},
+ "http://abc.com.xyz.com?q=abc.com",
+ false},
+ {{"abc.com^", kSubdomain, kBoundary}, "http://xyz.abc.com/123", false},
+ {{"abc.com^", kSubdomain, kBoundary}, "http://xyz.abc.com", true},
+ {{"abc.com^", kSubdomain, kBoundary},
+ "http://abc.com.xyz.com?q=abc.com/",
+ false},
+ {{"abc*^", kAnchorNone, kAnchorNone}, "https://abc.com", true},
+ {{"abc*^", kAnchorNone, kAnchorNone}, "https://abc.com?q=123", true},
+ {{"abc*^", kAnchorNone, kBoundary}, "https://abc.com", true},
+ {{"abc*^", kAnchorNone, kBoundary}, "https://abc.com?q=123", true},
};
for (const auto& test_case : kTestCases) {