Skip to content

Commit ad48307

Browse files
committed
Pull request 1173: AG-38806 $removeparam incorrectly removes parameters from encoded URLs
Squashed commit of the following: commit cc33faa Author: Maxim Topciu <[email protected]> Date: Thu Jan 23 06:37:14 2025 +0200 AG-38806 remove packs commit b517ecf Merge: 85d0be2 7b84768 Author: Maxim Topciu <[email protected]> Date: Thu Jan 23 06:35:53 2025 +0200 Merge branch 'master' into fix/AG-38806 commit 85d0be2 Author: Maxim Topciu <[email protected]> Date: Wed Jan 22 13:28:01 2025 +0200 AG-38806 build tgz commit 1521a11 Merge: 1913685 0201caf Author: Maxim Topciu <[email protected]> Date: Wed Jan 22 13:03:19 2025 +0200 Merge branch 'master' into fix/AG-38806 commit 1913685 Author: Maxim Topciu <[email protected]> Date: Mon Jan 20 16:26:25 2025 +0200 AG-38806 update names commit 215d94d Author: Maxim Topciu <[email protected]> Date: Mon Jan 20 16:24:28 2025 +0200 AG-38806 add packages for testing commit eec1307 Author: Maxim Topciu <[email protected]> Date: Mon Jan 20 16:06:20 2025 +0200 AG-38806 update changelog commit bdaaf10 Author: Maxim Topciu <[email protected]> Date: Mon Jan 20 16:02:40 2025 +0200 AG-38806 preserve params in encoded URLs for removeparam modifier
1 parent 7b84768 commit ad48307

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

packages/tsurlfilter/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2525
- URI encoded `$removeparam` value is not removed in MV3 [AdguardBrowserExtension#3014].
2626
- `$removeparam` fails to match encoded URL params in MV2 [AdguardBrowserExtension#3015].
2727
- `$popup,third-party` modifiers cause document blocking [AdguardBrowserExtension#3012].
28+
- `$removeparam` incorrectly removes parameters from encoded URLs [AdguardBrowserExtension#3076].
2829
- Pattern shortcut extraction from regexp patterns with character classes [AdguardBrowserExtension#2924].
2930

3031
[AdguardBrowserExtension#3014]: https://github.com/AdguardTeam/AdguardBrowserExtension/issues/3014
32+
[AdguardBrowserExtension#3015]: https://github.com/AdguardTeam/AdguardBrowserExtension/issues/3015
3133
[AdguardBrowserExtension#3012]: https://github.com/AdguardTeam/AdguardBrowserExtension/issues/3012
34+
[AdguardBrowserExtension#3076]: https://github.com/AdguardTeam/AdguardBrowserExtension/issues/3076
3235
[AdguardBrowserExtension#2924]: https://github.com/AdguardTeam/AdguardBrowserExtension/issues/2924
3336

3437
## [3.0.8] - 2024-11-25

packages/tsurlfilter/src/modifiers/remove-param-modifier.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ export class RemoveParamModifier implements IAdvancedModifier {
4545
throw new Error('Unsupported option in $removeparam: multiple values are not allowed');
4646
}
4747

48-
this.valueRegExp = new RegExp(`((^|&)(${SimpleRegex.escapeRegexSpecials(rawValue)})=[^&#]*)`, 'g');
48+
// no need to match "&" in the beginning, because we are splitting by "&"
49+
// https://github.com/AdguardTeam/AdguardBrowserExtension/issues/3076
50+
this.valueRegExp = new RegExp(`^${SimpleRegex.escapeRegexSpecials(rawValue)}=[^&#]*$`, 'g');
4951
}
5052
}
5153

packages/tsurlfilter/test/modifiers/advanced-modifier.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,22 @@ describe('NetworkRule - removeparam rules', () => {
471471
expect(modifier.removeParameters(`${comPage}?p0=0`)).toBe(`${comPage}?p0=0`);
472472
expect(modifier.removeParameters(`${comPage}?p0=0&p1=1`)).toBe(`${comPage}?p0=0&p1=1`);
473473
});
474+
475+
// https://github.com/AdguardTeam/AdguardBrowserExtension/issues/3076
476+
it('preserves parameters in encoded URLs', () => {
477+
const rule = createNetworkRule('$removeparam=utm_campaign', 0);
478+
const modifier = rule.getAdvancedModifier() as RemoveParamModifier;
479+
480+
const encodedUrl = `https://redirect.com/path?url=${encodeURIComponent('https://example.com?utm_source=test&utm_campaign=123')}`;
481+
482+
// Should preserve the encoded URL intact
483+
expect(modifier.removeParameters(encodedUrl)).toBe(encodedUrl);
484+
485+
// Should only remove top-level utm_campaign
486+
const mixedUrl = `https://redirect.com/path?utm_campaign=remove&url=${encodeURIComponent('https://example.com?utm_campaign=keep')}`;
487+
expect(modifier.removeParameters(mixedUrl))
488+
.toBe(`https://redirect.com/path?url=${encodeURIComponent('https://example.com?utm_campaign=keep')}`);
489+
});
474490
});
475491

476492
describe('NetworkRule - mv3 validity', () => {

0 commit comments

Comments
 (0)