From 19eaa52f7190e0a0c37da8503d4312494b67b4ec Mon Sep 17 00:00:00 2001 From: Elizaveta Egorova Date: Wed, 2 Oct 2024 19:13:13 +0300 Subject: [PATCH 1/3] Exclude `$redirect-rule` from filters for MV3 extension. #231 AG-36490 Squashed commit of the following: commit b8f7e6616e4d4d19de0bde264528fdc3ae29ed26 Author: jellizaveta Date: Wed Oct 2 18:13:59 2024 +0300 update script commit 0461cebeacd61ed2eb7a68ff9c6a293cea527dfb Author: jellizaveta Date: Wed Oct 2 17:08:19 2024 +0300 update changelog commit 2ce9506d13374256de1022381c823f9838a60597 Author: jellizaveta Date: Wed Oct 2 17:07:17 2024 +0300 update changelog commit 082b72069473560db74f1b87bd5471822c15d7dc Author: jellizaveta Date: Wed Oct 2 17:03:18 2024 +0300 Exclude -rule from filters for MV3 extension. #231 AG-36490 --- CHANGELOG.md | 10 +++++ src/main/platforms-config.js | 5 ++- src/test/builder.test.js | 41 +++++++++++++++++-- src/test/platforms-filter.test.js | 40 ++++++++++++++++++ .../filters/filter_5_TrustLevel/filter.txt | 1 + .../filters/filter_5_TrustLevel/revision.json | 6 +-- .../filters/filter_5_TrustLevel/template.txt | 1 + src/test/resources/platforms.json | 5 ++- 8 files changed, 101 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef96ad0..cb16da1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v1.1.148] - 2024-10-02 + +### Changed + +- Exclude `$redirect-rule` from filters for MV3 extension [#231] + +[v1.1.148]: https://github.com/AdguardTeam/FiltersCompiler/compare/v1.1.146...v1.1.148 +[#231]: https://github.com/AdguardTeam/FiltersCompiler/issues/231 + + ## [v1.1.146] - 2024-08-29 ### Added diff --git a/src/main/platforms-config.js b/src/main/platforms-config.js index 641a7f2..fbde5a5 100644 --- a/src/main/platforms-config.js +++ b/src/main/platforms-config.js @@ -606,7 +606,10 @@ module.exports = { 'path': 'extension/chromium-mv3', 'expires': '10 days', 'configuration': { - 'removeRulePatterns': CHROMIUM_BASED_EXTENSION_PATTERNS, + 'removeRulePatterns': [ + ...CHROMIUM_BASED_EXTENSION_PATTERNS, + ...REDIRECT_MODIFIER_PATTERNS, + ], 'replacements': null, 'ignoreRuleHints': false, }, diff --git a/src/test/builder.test.js b/src/test/builder.test.js index 52d247d..c4e992d 100644 --- a/src/test/builder.test.js +++ b/src/test/builder.test.js @@ -257,7 +257,7 @@ describe('Test builder', () => { it('platforms/test filters 5.txt', async () => { const filterContent = await readFile(path.join(__dirname, 'resources/platforms/test', 'filters', '5.txt')); const filterLines = filterContent.split(/\r?\n/); - expect(filterLines.length).toEqual(54); + expect(filterLines.length).toEqual(55); const presentRules = [ '||adsnet.com/*/700x350.gif$domain=example.com', @@ -293,7 +293,7 @@ describe('Test builder', () => { it('platforms/test2 filters 5.txt', async () => { const filterContent = await readFile(path.join(__dirname, 'resources/platforms/test2', 'filters', '5.txt')); const filterLines = filterContent.split(/\r?\n/); - expect(filterLines.length).toEqual(54); + expect(filterLines.length).toEqual(55); const presentRules = [ 'test.com#%#//scriptlet(\'abp-abort-on-property-read\', \'adsShown\')', @@ -584,6 +584,41 @@ describe('Test builder', () => { }); }); + it('platforms/chromium-mv3 filters 2.txt', async () => { + const filterContent = await readFile(path.join(platformsDir, 'chromium-mv3', 'filters', '2.txt')); + expect(filterContent).toBeTruthy(); + + const filterLines = filterContent.split(/\r?\n/); + expect(filterLines.length).toEqual(56); + + // expires value in set from the filters metadata + // if there is no 'expires' property in platform.json for the platform + expect(filterLines.includes('! Expires: 2 days (update frequency)')).toBeTruthy(); + + const presentLines = [ + 'test_domain#%#testScript();', + 'test.com#%#var isadblock=1;', + 'example.org#@%#navigator.getBattery = undefined;', + 'test.com#%#//scriptlet(\'ubo-abort-on-property-read.js\', \'Object.prototype.getBanner\')', + 'example.net#$?#.main-content { margin-top: 0!important; }', + 'test.com#@$?#.banner { padding: 0!important; }', + 'example.net#?#.banner:matches-css(width: 360px)', + 'test.com#@?#.banner:matches-css(height: 200px)', + ]; + presentLines.forEach((rule) => { + expect(filterLines.includes(rule)).toBeTruthy(); + }); + + const absentLines = [ + '||example.com^$script,redirect-rule=noopjs', + '*$redirect-rule=noopjs,xmlhttprequest,domain=example.com', + ]; + + absentLines.forEach((rule) => { + expect(filterLines.includes(rule)).toBeFalsy(); + }); + }); + describe('check MAC platform', () => { it('platform/mac filters.json', async () => { const macFiltersMetadataContent = await readFile(path.join(platformsDir, 'mac', 'filters.json')); @@ -701,7 +736,7 @@ describe('Test builder', () => { expect(filterContent).toBeTruthy(); const filterLines = filterContent.split(/\r?\n/); - expect(filterLines.length).toEqual(53); + expect(filterLines.length).toEqual(54); expect(filterLines.includes('||example.com^$script,redirect=noopjs')).toBeTruthy(); expect(filterLines.includes('||example.com/banner$image,redirect=1x1-transparent.gif')).toBeTruthy(); }); diff --git a/src/test/platforms-filter.test.js b/src/test/platforms-filter.test.js index 7de380d..a7775a8 100644 --- a/src/test/platforms-filter.test.js +++ b/src/test/platforms-filter.test.js @@ -179,6 +179,46 @@ describe('platforms filter', () => { expect(after).toEqual(notMatchRules); }); + it('Test removing `redirect-rule=` modifier', () => { + const config = { + 'platform': 'test', + 'path': 'hints', + 'configuration': { + 'removeRulePatterns': [ + '\\$redirect-rule=', + ',redirect-rule=', + ], + 'ignoreRuleHints': false, + }, + }; + + const notMatchRules = [ + '! Comment', + 'example.com', + 'example.com,content-examples.com###ad3', + '@@||example.com^$elemhide,content,jsinject', + '@@||example.com^$elemhide,jsinject,content', + '@@||content.com$stealth', + 'example.com##.sidebar_list > .widget_text:has(a[title = "content"])', + '||dai.google.com/ondemand/hls/content/*.m3u8$hls=/redirector\.googlevideo\.com\/,domain=sbs.com.au', + ]; + const matchRules = [ + '||example.com/script.json$xmlhttprequest,redirect-rule=noopjson', + '||example.com/script.js$script,redirect-rule=noopjs', + '*$redirect-rule=noopjs,xmlhttprequest,domain=example.com', + ]; + + const before = [ + ...notMatchRules, + ...matchRules, + ]; + + const after = filter.cleanupRules(before, config, 0); + + expect(after).toBeDefined(); + expect(after).toEqual(notMatchRules); + }); + it('Test removing of single content modifier', () => { const config = { 'platform': 'test', diff --git a/src/test/resources/filters/filter_5_TrustLevel/filter.txt b/src/test/resources/filters/filter_5_TrustLevel/filter.txt index 49b06c6..89ae0d4 100644 --- a/src/test/resources/filters/filter_5_TrustLevel/filter.txt +++ b/src/test/resources/filters/filter_5_TrustLevel/filter.txt @@ -44,4 +44,5 @@ example.com##div.grid_1[class$="app"] ||test.com^$script,redirect=noopjs ||example.com/*.mp4$media,redirect=noopmp4-1s ||example.com^$script,redirect-rule=noopjs +*$redirect-rule=noopjs,xmlhttprequest,domain=example.com ! diff --git a/src/test/resources/filters/filter_5_TrustLevel/revision.json b/src/test/resources/filters/filter_5_TrustLevel/revision.json index a5b237c..e37ac0b 100644 --- a/src/test/resources/filters/filter_5_TrustLevel/revision.json +++ b/src/test/resources/filters/filter_5_TrustLevel/revision.json @@ -1,5 +1,5 @@ { - "version": "1.0.0.1", - "timeUpdated": 1724275516306, - "hash": "w67DhUNcA8KqwoUuwqbCgcOdC33DnQQt" + "version": "1.0.0.3", + "timeUpdated": 1727881072037, + "hash": "Zm3CvkdZdU3Ci8O5Jmsfwr9ew7/DpQ==" } \ No newline at end of file diff --git a/src/test/resources/filters/filter_5_TrustLevel/template.txt b/src/test/resources/filters/filter_5_TrustLevel/template.txt index 926026d..26ee6a5 100644 --- a/src/test/resources/filters/filter_5_TrustLevel/template.txt +++ b/src/test/resources/filters/filter_5_TrustLevel/template.txt @@ -59,6 +59,7 @@ example.com##div.grid_1[class$="app"] ||test.com^$script,rewrite=abp-resource:blank-js ||example.com/*.mp4$media,redirect=noopmp4-1s ||example.com^$script,redirect-rule=noopjs +*$redirect-rule=noopjs,xmlhttprequest,domain=example.com ! example.com#%#//scriptlet('trusted-set-local-storage-item', 'iName', 'iValue') example.com#%#//scriptlet("trusted-set-cookie", "cName", "cValue") diff --git a/src/test/resources/platforms.json b/src/test/resources/platforms.json index 45f61ca..61305f2 100644 --- a/src/test/resources/platforms.json +++ b/src/test/resources/platforms.json @@ -113,7 +113,10 @@ "platform": "ext_chromium_mv3", "path": "chromium-mv3", "configuration": { - "removeRulePatterns": false, + "removeRulePatterns": [ + "\\$redirect-rule=", + ",redirect-rule=" + ], "ignoreRuleHints": false }, "defines": { From 3bdaca2e47ee9ba4a94ed310834bef3f0262deca Mon Sep 17 00:00:00 2001 From: Atlassian Bamboo Date: Wed, 2 Oct 2024 19:13:17 +0300 Subject: [PATCH 2/3] skipci: Automatic increment build number --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3509d00..780d223 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "adguard-filters-compiler", - "version": "1.1.146", + "version": "1.1.147", "description": "AdGuard filters compiler", "homepage": "http://adguard.com", "main": "index.js", From 1b11eb890aa6ee62e5e29b66155f269933db96bf Mon Sep 17 00:00:00 2001 From: Atlassian Bamboo Date: Wed, 2 Oct 2024 19:20:24 +0300 Subject: [PATCH 3/3] skipci: Automatic increment build number --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 780d223..f827faa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "adguard-filters-compiler", - "version": "1.1.147", + "version": "1.1.148", "description": "AdGuard filters compiler", "homepage": "http://adguard.com", "main": "index.js",