Skip to content

Read schema patterns as ECMAScript, as the browser does - #2557

Merged
max-sixty merged 4 commits into
mainfrom
cut-worker-rechecks
Oct 12, 2026
Merged

max-sixty merged 4 commits into
mainfrom
cut-worker-rechecks

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

JSON Schema defines pattern as an ECMAScript regular expression, and the browser reads it that way, but jsonschema searches it with Python's re, whose $ also matches before a final newline. So every ^…$ pattern at every Leaf boundary admitted a trailing newline: "abc\n" passed ^[a-z]+$ for element ids, reaction tokens, data-contract names and the rest. #2507 hit this and ended three patterns with a lookahead; this fixes it where every reader gets its validator.

  • jsonschema has no option for another regex engine; its keywords make one call, re.search, in two private modules (_keywords, _utils). registry/schema.py points that call at regress, an ECMAScript engine (Rust, compiled), with the u flag JSON Schema recommends. That covers pattern, patternProperties, and the additionalProperties/unevaluatedProperties accounting built on them, in every validator, a nested $schema included. A call jsonschema later adds to those modules fails loudly rather than reading Python's dialect; uv.lock pins the version the suite passed on.
  • check_schema holds the metaschema's regex format to the same engine, so an ECMAScript pattern Python refuses (\p{L}, (?<name>…)) is admitted and a Python-only one ((?P<name>…)) refused. All 40 distinct patterns in the tree compile.
  • The three (?![\s\S]) workarounds from Cut Python rechecks a stronger mechanism already enforces, and refuse a reply to a withdrawn message #2507 are plain $ again, and registry/layer.py's one direct Draft202012Validator goes through json_validator.
  • New runtime dependency regress>=2026.9, documented in pyproject.toml beside ada-url.

Behavior change: a string with a trailing newline no longer passes an anchored pattern, and a registry declaring a Python-only pattern is refused at page check/package check.

This was written by Claude Code on behalf of max-sixty

max-sixty and others added 2 commits October 12, 2026 01:44
jsonschema searches `pattern` and `patternProperties` with Python's re, whose
$ also matches before a final newline, so "abc\\n" passed ^[a-z]+$ at every
Leaf boundary while the browser refused it. LeafValidator reads both with
regress, an ECMAScript engine; check_schema refuses a pattern only Python reads;
the three lookahead workarounds go back to $.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ve patternProperties to jsonschema

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two regex paths still differ from the proposed ECMAScript contract. Both cases below reproduce on the current head.

max-sixty and others added 2 commits October 12, 2026 02:22
jsonschema has no option for another engine, and its keywords make one call,
re.search, in two modules; point those at regress, so patternProperties and the
additionalProperties and unevaluatedProperties accounting read keys as the
browser does, and hold check_schema's regex format to the same engine, so an
ECMAScript-only pattern such as \\p{L} is admitted and a Python-only one refused.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 76c0d00 into main Oct 12, 2026
5 checks passed
@max-sixty
max-sixty deleted the cut-worker-rechecks branch October 12, 2026 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants