Fix: Add wildcard (*) support for custom filters#586
Open
fresh3nough wants to merge 2 commits intobrave:masterfrom
Open
Fix: Add wildcard (*) support for custom filters#586fresh3nough wants to merge 2 commits intobrave:masterfrom
fresh3nough wants to merge 2 commits intobrave:masterfrom
Conversation
added 2 commits
January 18, 2026 09:33
Fixes brave#582 This change allows the use of wildcard (*) in cosmetic filters, including scriptlet injection rules like *##+js(filter). The wildcard is now properly treated as matching all domains by skipping it during domain parsing, making it equivalent to a generic filter but without triggering the GenericScriptInject error. Changes: - Modified locations_before_sharp() to skip wildcard (*) domains - Added comprehensive tests for wildcard support including: - Scriptlet injection with wildcards - Regular cosmetic filters with wildcards - Wildcards combined with specific domains
The hash changed because wildcards now correctly have no hostname constraints, changing the serialized format. This is the expected behavior after the wildcard support fix.
antonok-edm
reviewed
Jan 21, 2026
Collaborator
antonok-edm
left a comment
There was a problem hiding this comment.
Hi, thanks for your contribution.
The only thing ignoring the wildcard token will do is save a tiny bit of runtime memory by not storing the hashed * character associated with the relevant rules.
For this to actually work, it will need to be put into a structure that can be queried at runtime.
The tests you added only test parsing, not matching behavior.
Also fwiw, *,example.com doesn't make any sense as part of a rule - why call out example.com specifically if the wildcard is already there?
Author
|
Fixed all the issues:
The wildcard filters now work as generic rules - |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #582
This PR adds support for wildcard (
*) syntax in cosmetic filters, particularly for scriptlet injection rules like*##+js(filter). This brings adblock-rust's behavior in line with uBlock Origin and enables filter list authors to apply scriptlets globally across all domains.Problem
Previously, filters using the wildcard syntax
*##+js(scriptlet)would parse successfully but fail to match any domains. The parser treated*as a literal hostname rather than recognizing it as a wildcard meaning "all domains". This caused the filter to have hostname constraints that would never match.Solution
The fix is minimal and elegant - we simply skip the
*wildcard during domain parsing in thelocations_before_sharp()function