support non-latin characters in matches-path
This commit is contained in:
@@ -2827,10 +2827,14 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, ProceduralFilterMatchesPath) {
|
||||
"p.odd:matches-path(cosmetic_filtering.html)\n"
|
||||
"a.com##:matches-path(/c[aeiou]smetic\\_[a-z]{9}/) section "
|
||||
".positive-regex-case p.odd\n"
|
||||
"a.com##section .negative-case:matches-path(/some-other-page.html)");
|
||||
"a.com##section .negative-case:matches-path(/some-other-page.html)\n"
|
||||
"a.com##:matches-path(😎) section .positive-unicode-case p.odd");
|
||||
|
||||
GURL tab_url =
|
||||
embedded_test_server()->GetURL("a.com", "/cosmetic_filtering.html");
|
||||
GURL::Replacements replacements;
|
||||
replacements.SetQueryStr("😎");
|
||||
GURL tab_url = embedded_test_server()
|
||||
->GetURL("a.com", "/cosmetic_filtering.html")
|
||||
.ReplaceComponents(replacements);
|
||||
NavigateToURL(tab_url);
|
||||
|
||||
content::WebContents* contents = web_contents();
|
||||
|
||||
@@ -123,6 +123,7 @@ const _extractKeyMatchRuleFromStr = (text: string): [TextMatchRule, number] => {
|
||||
}
|
||||
|
||||
const _extractValueMatchRuleFromStr = (text: string,
|
||||
uriEncode = false,
|
||||
needlePosition = 0): TextMatchRule => {
|
||||
const isQuotedCase = text[needlePosition] === '"'
|
||||
let endIndex
|
||||
@@ -140,7 +141,10 @@ const _extractValueMatchRuleFromStr = (text: string,
|
||||
endIndex = text.length
|
||||
}
|
||||
|
||||
const testCaseStr = text.slice(needlePosition, endIndex)
|
||||
let testCaseStr = text.slice(needlePosition, endIndex)
|
||||
if (uriEncode) {
|
||||
testCaseStr = testCaseStr.replace(/\P{ASCII}/gu, c => encodeURIComponent(c))
|
||||
}
|
||||
const testCaseFunc = _testMatches.bind(undefined, testCaseStr)
|
||||
return testCaseFunc
|
||||
}
|
||||
@@ -159,7 +163,7 @@ const _extractValueMatchRuleFromStr = (text: string,
|
||||
// }
|
||||
const _parseKeyValueMatchRules = (arg: string): KeyValueMatchRules => {
|
||||
const [keyMatchRule, needlePos] = _extractKeyMatchRuleFromStr(arg)
|
||||
const valueMatchRule = _extractValueMatchRuleFromStr(arg, needlePos)
|
||||
const valueMatchRule = _extractValueMatchRuleFromStr(arg, false, needlePos)
|
||||
return [keyMatchRule, valueMatchRule]
|
||||
}
|
||||
|
||||
@@ -387,7 +391,7 @@ const operatorMatchesMedia = (instruction: string,
|
||||
const operatorMatchesPath = (instruction: string,
|
||||
element: HTMLElement): OperatorResult => {
|
||||
const pathAndQuery = W.location.pathname + W.location.search
|
||||
const matchRule = _extractValueMatchRuleFromStr(instruction)
|
||||
const matchRule = _extractValueMatchRuleFromStr(instruction, true)
|
||||
return matchRule(pathAndQuery) ? [element] : []
|
||||
}
|
||||
|
||||
|
||||
@@ -288,6 +288,13 @@ const classes = (expectedClasses) =>
|
||||
<p data-expect="visible">Should not be hidden</p>
|
||||
</div>
|
||||
|
||||
<div class="positive-unicode-case">
|
||||
<h2><code>:matches-path</code>: positive unicode case</h2>
|
||||
<p class="odd" data-expect="hidden">Should be hidden</p>
|
||||
<p class="even" data-expect="visible">Should not be hidden</p>
|
||||
<p data-expect="visible">Should not be hidden</p>
|
||||
</div>
|
||||
|
||||
<div class="negative-case">
|
||||
<h2><code>:matches-path</code>: negative case</h2>
|
||||
<p class="odd" data-expect="visible">Should not be hidden</p>
|
||||
|
||||
Reference in New Issue
Block a user