fix: anchor string patterns in match() to consume full keypath#579
Open
gaoflow wants to merge 1 commit into
Open
fix: anchor string patterns in match() to consume full keypath#579gaoflow wants to merge 1 commit into
gaoflow wants to merge 1 commit into
Conversation
String patterns like '*a' were matched with regex.match() which only checks a prefix, so '(.)*a' matched 'ab' (consuming just 'a', leaving 'b' unconsumed). Fix by appending '$' to string-derived patterns so the entire keypath must be consumed. Raw compiled-regex patterns are unaffected and continue to use match() as before.
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.
Bug
benedict.match()converts string wildcard patterns to regex and appliesregex.match(), which only verifies a prefix match — the rest of thekeypath is silently ignored.
For a pattern like
"*a"the transformation produces(.)*a. Becauseregex.match("ab")anchors at the start but not the end, it succeeds on"ab"(.consumes"a",amatches the first character,"b"isleft unconsumed). The result: keys that do not end in
"a"areerroneously returned.
Fix
Append
"$"to string-derived patterns before compiling so the fullkeypath must be consumed. Raw compiled-regex patterns (
re.Pattern)are unaffected and continue to use
regex.match()as before.Tests
Added
test_match_with_suffix_wildcardtotests/core/test_match.py;all 261 existing core + keypath tests continue to pass.