From ed58d6aba4b2f82733ffa83e7cd304844a786817 Mon Sep 17 00:00:00 2001 From: Krzysztof Modras Date: Wed, 20 Sep 2023 11:14:48 +0200 Subject: [PATCH] DNR: fix detection of regexp lookahead and lookbehind --- .../abstract-rule-converter.ts | 2 +- .../declarative-converter.test.ts | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/tsurlfilter/src/rules/declarative-converter/grouped-rules-converters/abstract-rule-converter.ts b/packages/tsurlfilter/src/rules/declarative-converter/grouped-rules-converters/abstract-rule-converter.ts index d5b559754..209a6b847 100644 --- a/packages/tsurlfilter/src/rules/declarative-converter/grouped-rules-converters/abstract-rule-converter.ts +++ b/packages/tsurlfilter/src/rules/declarative-converter/grouped-rules-converters/abstract-rule-converter.ts @@ -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]|(? { }); }); + 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([