Skip to content

Fix Wildcard#match? matching a wildcard rule against its own value#549

Open
chatman-media wants to merge 1 commit into
weppos:mainfrom
chatman-media:fix-wildcard-rule-exact-match
Open

Fix Wildcard#match? matching a wildcard rule against its own value#549
chatman-media wants to merge 1 commit into
weppos:mainfrom
chatman-media:fix-wildcard-rule-exact-match

Conversation

@chatman-media

Copy link
Copy Markdown

*.com's match? should only be true for names with at least one label before com (that's what the wildcard is for), but Rule::Base#match? treats an exact match against value as a hit too, so match?("com") for the *.com rule comes back true - same as a plain com rule would. There's even a commented-out FIXME test for exactly this in rule_test.rb already.

decompose/the actual parsing pipeline aren't affected since they use their own regex, but match? is a documented public method and gives the wrong answer if you call it directly on a wildcard rule.

Added an override in Wildcard that requires the extra label, uncommented the FIXME'd test case and added a couple more (multi-label wildcard value, plus a dedicated test_match in RuleWildcardTest).

A wildcard rule like *.com requires an extra label before it, but
Rule::Base#match? was chomping the value off and calling it a match
whenever the diff was empty - so match?("com") returned true for the
*.com rule, same as it would for a plain "com" rule. There's actually
a FIXME comment marking this exact case in the tests already.

Added a Wildcard#match? override that requires the extra label (i.e.
the diff must end with a dot, not just be empty), and uncommented/
extended the test case.
@weppos weppos self-assigned this Jul 6, 2026
@weppos weppos added the bug label Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants