Skip to content

Commit

Permalink
DNR: fix detection of regexp lookahead and lookbehind
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmod committed Sep 20, 2023
1 parent 4855ebd commit ed58d6a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ export abstract class DeclarativeRuleConverter {

// Back reference, possessive and negative lookahead are not supported
// See more: https://github.com/google/re2/wiki/Syntax
if (regexFilter?.match(/\\[1-9]|(?<!\\)\?|{\S+}/g)) {
if (regexFilter?.match(/\\[1-9]|\(\?<?(!|=)|{\S+}/g)) {
const msg = `Invalid regex in the: "${networkRule.getText()}"`;
return new UnsupportedRegexpError(
msg,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,27 @@ describe('DeclarativeConverter', () => {
});
});

it('converts simple blocking regexp rule with ? quantifier', async () => {
const filter = createFilter(['/aaa?/']);
const { ruleSets: [ruleSet] } = await converter.convert(
[filter],
);
const { declarativeRules } = await ruleSet.serialize();

const ruleId = 1;

expect(declarativeRules).toHaveLength(1);
expect(declarativeRules[0]).toEqual({
id: ruleId,
action: { type: 'block' },
condition: {
regexFilter: '/aaa?/',
isUrlFilterCaseSensitive: false,
},
priority: 1,
});
});

describe('respects badfilter rules', () => {
it('applies $badfilter to one filter', async () => {
const filter = createFilter([
Expand Down

0 comments on commit ed58d6a

Please sign in to comment.