From 250cf96aae187a5c31c7fb2311ef5baea504bff1 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 23 Jan 2022 12:32:11 -0500 Subject: [PATCH] Fix regression causing regex-based filters to be case sensitive Related feedback: - https://github.com/AdguardTeam/AdguardFilters/issues/88067#issuecomment-1019518277 Regression commit: - https://github.com/gorhill/uBlock/commit/725e6931f58a81d36b18bb78663a8740c5e36231 --- platform/npm/tests/snfe.js | 25 +++++++++++++++++++++++++ src/js/static-net-filtering.js | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/platform/npm/tests/snfe.js b/platform/npm/tests/snfe.js index f0ee86b57..b1cee181c 100644 --- a/platform/npm/tests/snfe.js +++ b/platform/npm/tests/snfe.js @@ -341,6 +341,31 @@ describe('SNFE', () => { }); assert.strictEqual(r, 0); }); + + // https://github.com/AdguardTeam/AdguardFilters/issues/88067#issuecomment-1019518277 + it('should match regex-based filter without `match-case` option', async () => { + await engine.useLists([ + { name: 'test', raw: '/\.com\/[a-z]{9,}\/[a-z]{9,}\.js$/$script,1p' }, + ]); + const r = engine.matchRequest({ + originURL: 'https://example.com/', + type: 'script', + url: 'https://example.com/LQMDQSMLDAZAEHERE/LQMDQSMLDAZAEHERE.js', + }); + assert.strictEqual(r, 1); + }); + + it('should not match regex-based filter with `match-case` option', async () => { + await engine.useLists([ + { name: 'test', raw: '/\.com\/[a-z]{9,}\/[a-z]{9,}\.js$/$script,1p,match-case' }, + ]); + const r = engine.matchRequest({ + originURL: 'https://example.com/', + type: 'script', + url: 'https://example.com/LQMDQSMLDAZAEHERE/LQMDQSMLDAZAEHERE.js', + }); + assert.strictEqual(r, 0); + }); }); }); } diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js index e96bb8b82..f28c6ca10 100644 --- a/src/js/static-net-filtering.js +++ b/src/js/static-net-filtering.js @@ -1108,7 +1108,7 @@ const FilterRegex = class { if ( refs.$re === null ) { refs.$re = new RegExp( this.getRegexPattern(idata), - filterData[idata+3] === 0 ? '' : 'i' + filterData[idata+3] === 0 ? 'i' : '' ); } if ( refs.$re.test($requestURLRaw) === false ) { return false; }