From 7d9b386f3fce395181823de464a69df8bd1a3107 Mon Sep 17 00:00:00 2001 From: Stanislav Atroschenko Date: Wed, 27 Sep 2023 21:02:41 +0300 Subject: [PATCH] AG-25278 allow removeparam service to modify urls of POST requests Merge in ADGUARD-FILTERS/tsurlfilter from fix/AG-25278 to release/v2.2 Squashed commit of the following: commit 4057d300d99fc228442d5f54172410a0a22c4d43 Merge: 0e626a00 34c76781 Author: Stanislav A Date: Wed Sep 27 20:47:25 2023 +0300 Merge branch 'release/v2.2' into fix/AG-25278 commit 0e626a0021bb81b70b5e901be887e8b1dd38e2df Author: Stanislav A Date: Wed Sep 20 14:39:54 2023 +0300 remove todo commit 4be108b78c1d5f206df11b6a1095c9c0377e8e35 Author: Stanislav A Date: Tue Sep 19 19:23:42 2023 +0300 fix typo commit bfcd43084387a46f1e4bf8aa4efceac1a99bde74 Author: Stanislav A Date: Tue Sep 19 19:12:11 2023 +0300 add todo commit 1ed809225d52e077672a420d6d50ede1850ca0c1 Author: Stanislav A Date: Tue Sep 19 19:11:09 2023 +0300 update changelog commit 311580d998e747da82d2a11826053c760b4c9c14 Author: Stanislav A Date: Tue Sep 19 19:10:10 2023 +0300 allow removeparamservice to modify urls of POST requests --- packages/tswebextension/CHANGELOG.md | 5 +++++ .../src/lib/mv2/background/services/params-service.ts | 2 +- .../lib/mv2/background/services/params-service.test.ts | 9 ++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/tswebextension/CHANGELOG.md b/packages/tswebextension/CHANGELOG.md index 5c9000d7be..c07ec6ac01 100644 --- a/packages/tswebextension/CHANGELOG.md +++ b/packages/tswebextension/CHANGELOG.md @@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 +## [Unreleased] + +### Added +- Support for `POST` requests to `$removeparam` modifier [#99](https://github.com/AdguardTeam/tsurlfilter/issues/99). + ## [0.4.5] - 2023-11-15 diff --git a/packages/tswebextension/src/lib/mv2/background/services/params-service.ts b/packages/tswebextension/src/lib/mv2/background/services/params-service.ts index 507799854c..3f272b505c 100644 --- a/packages/tswebextension/src/lib/mv2/background/services/params-service.ts +++ b/packages/tswebextension/src/lib/mv2/background/services/params-service.ts @@ -24,7 +24,7 @@ export class ParamsService { this.filteringLog = filteringLog; } - private static SupportedMethods = ['GET', 'OPTIONS', 'HEAD']; + private static SupportedMethods = ['GET', 'POST', 'OPTIONS', 'HEAD']; /** * Removes request params from url, stored in request context. diff --git a/packages/tswebextension/test/lib/mv2/background/services/params-service.test.ts b/packages/tswebextension/test/lib/mv2/background/services/params-service.test.ts index 9b3b989155..aecc90e238 100644 --- a/packages/tswebextension/test/lib/mv2/background/services/params-service.test.ts +++ b/packages/tswebextension/test/lib/mv2/background/services/params-service.test.ts @@ -57,7 +57,7 @@ describe('Params service', () => { expect(purgedUrl).toBe(null); }); - it('removes get request params', () => { + it('removes GET request params', () => { const purgedUrl = testUrlPurge( 'https://example.org?param=1', 'GET', @@ -70,14 +70,17 @@ describe('Params service', () => { ); }); - it('ignores post request params', () => { + it('removes POST request params', () => { const purgedUrl = testUrlPurge( 'https://example.org?param=1', 'POST', ['||example.org^$removeparam'], ); - expect(purgedUrl).toBe(null); + expect(purgedUrl).toBe('https://example.org'); + expect(mockFilteringLog.publishEvent).toHaveBeenCalledWith( + expect.objectContaining({ type: FilteringEventType.RemoveParam }), + ); }); it('correctly processes allowlist rule', () => {