adblock-rust icon indicating copy to clipboard operation
adblock-rust copied to clipboard

Support regex rules with an end-anchor (`$`)

Open antonok-edm opened this issue 2 years ago • 6 comments

Consider the following filter:

/^https?:\/\/[a-z]{8,15}\.top\/[a-z]{4,}\.json$/$xhr,3p,match-case

There are two $ characters in the filter. The first represents an anchor to the end of a URL, and the second separates the pattern part of the filter from the options.

adblock-rust currently treats the first $ character as the separator, such that the pattern no longer ends with a / character. match-case is only supported for regex rules, so the rule is ultimately considered invalid.

antonok-edm avatar Feb 01 '23 09:02 antonok-edm

AdGuard support match-case for all network filters: https://adguard.com/kb/ko/general/ad-filtering/create-own-filters/#match-case-modifier

Same Adblock Plus: https://testpages.adblockplus.org/en/filters/match-case

Only uBo don't see reason to implement wider than regex (where someone intentionally used [A-Z] instead [a-z] that can match capital letters in network filtering normaly).

krystian3w avatar Feb 11 '23 15:02 krystian3w

Hello @antonok-edm, How can I regenerate this issue and Test it once I apply the solution?

buddhdev-harsh avatar Aug 15 '23 04:08 buddhdev-harsh

@harshdevl if you'd like to give this a try you can check the network filter parsing code. You could test this by writing some parsing unit tests similar to the ones starting here.

If you've successfully parsed the above filter, the filter field should include the first $ character.

antonok-edm avatar Aug 17 '23 02:08 antonok-edm

to keep it simple, and based on what I have understood so far. I was planning to make this regex change here.

buddhdev-harsh avatar Aug 17 '23 02:08 buddhdev-harsh

I'd strongly recommend unit testing at the network filter level; the Engine tests may be too high-level to confirm that the parsing is correct.

antonok-edm avatar Aug 17 '23 03:08 antonok-edm

Got it. Thanks.

buddhdev-harsh avatar Aug 17 '23 03:08 buddhdev-harsh