diff --git a/packages/tsurlfilter/CHANGELOG.md b/packages/tsurlfilter/CHANGELOG.md index 695d600b41..b20560d362 100644 --- a/packages/tsurlfilter/CHANGELOG.md +++ b/packages/tsurlfilter/CHANGELOG.md @@ -8,6 +8,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 +## [3.0.7] - 2024-11-18 + +### Fixed + +- `$removeparam` fails to match encoded URL params in MV2 [AdguardBrowserExtension#3015]. + +[AdguardBrowserExtension#3015]: https://github.com/AdguardTeam/AdguardBrowserExtension/issues/3015 +[3.0.7]: https://github.com/AdguardTeam/tsurlfilter/releases/tag/tsurlfilter-v3.0.7 + ## [3.0.6] - 2024-11-02 ### Changed diff --git a/packages/tsurlfilter/package.json b/packages/tsurlfilter/package.json index ea5570f061..da1bb21f89 100644 --- a/packages/tsurlfilter/package.json +++ b/packages/tsurlfilter/package.json @@ -1,6 +1,6 @@ { "name": "@adguard/tsurlfilter", - "version": "3.0.6", + "version": "3.0.7", "description": "This is a TypeScript library that implements AdGuard's content blocking rules", "main": "dist/es/index.js", "module": "dist/es/index.js", diff --git a/packages/tsurlfilter/src/utils/url.ts b/packages/tsurlfilter/src/utils/url.ts index b906099954..280cfdec5b 100644 --- a/packages/tsurlfilter/src/utils/url.ts +++ b/packages/tsurlfilter/src/utils/url.ts @@ -64,19 +64,23 @@ export function cleanUrlParamByRegExp(url: string, regExp: RegExp, invert = fals const split = splitUrl(url); + /** + * We are checking both regular param and decoded param, in case if regexp + * contains decoded params and url contains encoded params: + * https://github.com/AdguardTeam/AdguardBrowserExtension/issues/3015 + */ let modifiedQuery; if (invert) { modifiedQuery = split.query .split('&') - .filter((x) => x) - .filter((x) => x && x.match(regExp)) + .filter((x) => x && (x.match(regExp) || decodeURIComponent(x).match(regExp))) .join('&'); } else { modifiedQuery = split.query .split('&') .filter((x) => { const test = x.includes('=') ? x : `${x}=`; - return !test.match(regExp); + return !test.match(regExp) && !decodeURIComponent(test).match(regExp); }) .join('&'); } diff --git a/packages/tsurlfilter/test/modifiers/advanced-modifier.test.ts b/packages/tsurlfilter/test/modifiers/advanced-modifier.test.ts index b86b01b57e..fa032492fa 100644 --- a/packages/tsurlfilter/test/modifiers/advanced-modifier.test.ts +++ b/packages/tsurlfilter/test/modifiers/advanced-modifier.test.ts @@ -353,7 +353,7 @@ describe('NetworkRule - removeparam rules', () => { }); it('works if query parameters are correctly filtered with regexp', () => { - const rule = createNetworkRule('$removeparam=/p1|p2|p3|p4_.*/i', 0); + const rule = createNetworkRule('$removeparam=/p1|p2|p3|p4_|\\$p5.*/i', 0); const modifier = rule.getAdvancedModifier() as RemoveParamModifier; const comPage = 'http://example.com/page'; @@ -366,6 +366,7 @@ describe('NetworkRule - removeparam rules', () => { expect(modifier.removeParameters(`${comPage}?p0=0&p4_=4`)).toBe(`${comPage}?p0=0`); expect(modifier.removeParameters(`${comPage}?p0=0&p4=4`)).toBe(`${comPage}?p0=0&p4=4`); expect(modifier.removeParameters(`${comPage}?p0=0&p4_1=4`)).toBe(`${comPage}?p0=0`); + expect(modifier.removeParameters(`${comPage}?p0=0&%24p5=0&$p5=0&p5=0`)).toBe(`${comPage}?p0=0&p5=0`); }); it('works if query parameters are removed by naked rule', () => { @@ -390,7 +391,7 @@ describe('NetworkRule - removeparam rules', () => { }); it('works if inverted regex removeparam is applied correctly', () => { - const rule = createNetworkRule('$removeparam=~/p0.*/', 0); + const rule = createNetworkRule('$removeparam=~/p0|\\$p4.*/', 0); const modifier = rule.getAdvancedModifier() as RemoveParamModifier; const comPage = 'http://example.com/page'; @@ -398,6 +399,7 @@ describe('NetworkRule - removeparam rules', () => { expect(modifier.removeParameters(`${comPage}?p0=0`)).toBe(`${comPage}?p0=0`); expect(modifier.removeParameters(`${comPage}?p0=0&p1=1`)).toBe(`${comPage}?p0=0`); expect(modifier.removeParameters(`${comPage}?p01=0&p1=1&p2=2&p3=3`)).toBe(`${comPage}?p01=0`); + expect(modifier.removeParameters(`${comPage}?p0=0&p1=2&p2=2&p3=3&%24p4=0&$p4=0&p4=0`)).toBe(`${comPage}?p0=0&%24p4=0&$p4=0`); }); it('does not remove unmatched parameters', () => { diff --git a/packages/tsurlfilter/test/utils/url.test.ts b/packages/tsurlfilter/test/utils/url.test.ts index 405fa5a06e..0897c021f4 100644 --- a/packages/tsurlfilter/test/utils/url.test.ts +++ b/packages/tsurlfilter/test/utils/url.test.ts @@ -31,4 +31,11 @@ describe('Query parameters', () => { expect(utils.cleanUrlParamByRegExp('http://example.com?test=1&test=2', /test.*/, true)).toEqual('http://example.com?test=1&test=2'); expect(utils.cleanUrlParamByRegExp('http://example.com?test=1&test=2', /test=1/, true)).toEqual('http://example.com?test=1'); }); + + it('handles properly encoded params', () => { + expect(utils.cleanUrlParamByRegExp('http://example.com?$test', /\$test.*/)).toEqual('http://example.com'); + expect(utils.cleanUrlParamByRegExp('http://example.com?%24test', /\$test.*/)).toEqual('http://example.com'); + expect(utils.cleanUrlParamByRegExp('http://example.com?$test', /\$test.*/, true)).toEqual('http://example.com?$test'); + expect(utils.cleanUrlParamByRegExp('http://example.com?%24test', /\$test.*/, true)).toEqual('http://example.com?%24test'); + }); }); diff --git a/packages/tswebextension/CHANGELOG.md b/packages/tswebextension/CHANGELOG.md index f01e99407d..571cf3413e 100644 --- a/packages/tswebextension/CHANGELOG.md +++ b/packages/tswebextension/CHANGELOG.md @@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 +## [2.0.6] - 2024-11-18 + +- Updated `@adguard/tsurlfilter` to `v3.0.7`. + +[2.0.6]: https://github.com/AdguardTeam/tsurlfilter/releases/tag/tswebextension-v2.0.6 + ## [2.0.5] - 2024-11-02 ### Changed diff --git a/packages/tswebextension/package.json b/packages/tswebextension/package.json index 7b3946b290..f5412a33dc 100644 --- a/packages/tswebextension/package.json +++ b/packages/tswebextension/package.json @@ -1,6 +1,6 @@ { "name": "@adguard/tswebextension", - "version": "2.0.5", + "version": "2.0.6", "description": "This is a TypeScript library that implements AdGuard's extension API", "main": "dist/index.js", "typings": "dist/types/src/lib/mv2/background/index.d.ts",