diff --git a/browser/brave_shields/ad_block_service_browsertest.cc b/browser/brave_shields/ad_block_service_browsertest.cc index 50d280f20c4..1afd394efa8 100644 --- a/browser/brave_shields/ad_block_service_browsertest.cc +++ b/browser/brave_shields/ad_block_service_browsertest.cc @@ -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(); diff --git a/components/cosmetic_filters/resources/data/procedural_filters.ts b/components/cosmetic_filters/resources/data/procedural_filters.ts index 4746c23373a..838efbb6b67 100644 --- a/components/cosmetic_filters/resources/data/procedural_filters.ts +++ b/components/cosmetic_filters/resources/data/procedural_filters.ts @@ -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] : [] } diff --git a/test/data/cosmetic_filtering.html b/test/data/cosmetic_filtering.html index 78cac7c6651..8fd5d302cd1 100644 --- a/test/data/cosmetic_filtering.html +++ b/test/data/cosmetic_filtering.html @@ -288,6 +288,13 @@ const classes = (expectedClasses) =>
Should not be hidden
+:matches-path: positive unicode caseShould be hidden
+Should not be hidden
+Should not be hidden
+:matches-path: negative caseShould not be hidden