Repository navigation
Conversation
Replace DOLLAR_FINDER with a scanner that tracks backslash parity and character-class state. This stops rewriting a literal $ inside [...], and correctly anchors $ after an even number of backslashes in pattern and patternProperties.
This branch has not been deployed
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.
Problem
DOLLAR_FINDERrewrites an unescaped$to Python's\Zso that JSON Schemapatterngets ECMA-262 end-of-input behavior instead of Python's$(which also matches before a final newline). The rewrite is:It has two issues:
\\$, the$is an anchor after a literal backslash, but the negative lookbehind sees a backslash and leaves it unchanged. Python then accepts"\\\n", although ECMA-262 requires the input to end after the backslash.$inside a character class is rewritten.[$]becomes[\Z], which Python rejects withre.PatternError: bad escape \Z.Both
patternandpatternPropertiesare affected;propertyNamesreaches the same code throughpattern.Reproduction
The parity failure also reproduces through
patternProperties:Expected behavior
JSON Schema Validation 2020-12 §6.3.3 requires
patternto be a valid ECMA-262 regular expression and notes that patterns are not implicitly anchored. ECMA-262$asserts end of input unless themflag is set; JSON Schema does not setm.Bun 1.3.14 confirms the oracle:
[$]is a character class containing a literal dollar sign and must compile and match strings containing$.Fix
Replace the regex substitution with a small scanner that tracks escape state and character-class state:
Both call sites use it:
The scanner preserves
\$and$inside[...], still rewrites unescaped$outside classes, and handles an even number of backslashes because escape state is consumed pairwise.DOLLAR_FINDERand its misleading comment are removed.Tests
Added
tests/test_pattern_dollar_character_class.py, covering:[$],[^$],[a$],[\$], and[]]inpattern;$after two and four backslashes, including rejection of a trailing newline;patternPropertieswithadditionalProperties: False;propertyNameswithpattern: "[$]".Results on
89805b9:8 failed, 3 passed.183 passedacross the affected modules (test_pattern_dollar_character_class.py,test_string.py,test_pattern_properties.py,test_object.py).qa_harness.py:{"ok": true, "drafts": 5, "checks": 208, "failures": []}. The same harness exits 1 with 39 failures on the original source.Prior art
DOLLAR_FINDERand explicitly documented that[$]would need to be written as[\$]. That is a known limitation, not a new discovery.patternProperties.The parity bug is the primary fix here; the class crash is fixed at the same time because both come from the same helper.
Changelog
Added under
=== UNRELEASED: