From a8a46c4593771c83b725ebe35a287c47146f0c0c Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 26 Mar 2023 15:37:15 -0400 Subject: [PATCH] Normalize non-ASCII characters in `:matches-path()` argument Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/2369 --- platform/mv3/extension/js/scripting/css-procedural.js | 4 +++- src/js/contentscript-extra.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/platform/mv3/extension/js/scripting/css-procedural.js b/platform/mv3/extension/js/scripting/css-procedural.js index 364bd41f4..f8fc6f0a1 100644 --- a/platform/mv3/extension/js/scripting/css-procedural.js +++ b/platform/mv3/extension/js/scripting/css-procedural.js @@ -192,7 +192,9 @@ class PSelectorMatchesMediaTask extends PSelectorTask { class PSelectorMatchesPathTask extends PSelectorTask { constructor(task) { super(); - this.needle = regexFromString(task[1]); + this.needle = regexFromString( + task[1].replace(/\P{ASCII}/gu, s => encodeURIComponent(s)) + ); } transpose(node, output) { if ( this.needle.test(self.location.pathname + self.location.search) ) { diff --git a/src/js/contentscript-extra.js b/src/js/contentscript-extra.js index 344165693..29a736d21 100644 --- a/src/js/contentscript-extra.js +++ b/src/js/contentscript-extra.js @@ -161,7 +161,9 @@ class PSelectorMatchesMediaTask extends PSelectorTask { class PSelectorMatchesPathTask extends PSelectorTask { constructor(task) { super(); - this.needle = regexFromString(task[1]); + this.needle = regexFromString( + task[1].replace(/\P{ASCII}/gu, s => encodeURIComponent(s)) + ); } transpose(node, output) { if ( this.needle.test(self.location.pathname + self.location.search) ) {