Fix regression causing regex-based filters to be case sensitive

Related feedback:
- https://github.com/AdguardTeam/AdguardFilters/issues/88067#issuecomment-1019518277

Regression commit:
- 725e6931f5
This commit is contained in:
Raymond Hill 2022-01-23 12:32:11 -05:00
parent f4824bd0d9
commit 250cf96aae
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 26 additions and 1 deletions

View File

@ -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);
});
});
});
}

View File

@ -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; }