Repository navigation
Anchor $ to end of string in patternProperties regexes - #232
Merged
Merged
Conversation
Owner
|
Could you please rebase? 🙏 |
generate_pattern replaces an unescaped $ with \Z so it matches only at
the end of the string, as in ECMA 262, but generate_pattern_properties
compiled the regex as is. Python's $ also matches before a trailing
newline, so with patternProperties {'^[a-z]+$': {}} and
additionalProperties false a key 'abc\n' was accepted.
Both keywords store the compiled regex in REGEX_PATTERNS under the
original pattern string, so when a pattern and a patternProperties key
use the same regex the unfixed one overwrote the fixed one and the
pattern keyword accepted 'abc\n' too. Apply the same substitution in
generate_pattern_properties.
kakkar87d
force-pushed
the
pattern-properties-end-anchor
branch
from
November 2, 2026 07:26
1bf6f40 to
cc050a2
Compare
Contributor
Author
|
Rebased on 2.22.3. The only conflict was the changelog, so the entry is now under a new UNRELEASED section. |
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.
$in patternProperties matches before a trailing newlinegenerate_patternrewrites an unescaped$to\Zso it only matches at the end of the string (ECMA 262 semantics), butgenerate_pattern_propertiescompiles the regex unchanged, so Python's$also matches before a final\n:The second case happens because both keywords store the compiled regex in
REGEX_PATTERNSunder the original pattern string, so the unfixed patternProperties compile overwrites the fixed one used bypattern. Two tests intests/test_pattern_properties.pycover both cases; they fail onmasterand pass with this change, and the rest of the suite passes.CHANGELOG.txthas an entry under UNRELEASED.