Repository navigation
json-schema : accept escaped hyphen in regex patterns - #29127
Conversation
|
Hi @ChihebBENCHEIKH1, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
|
/bot review |
Automated code reviewReviewed the diff (
Correctness checks on edge cases around the verbatim copy into char classes:
The two new tests' expected outputs match what the code actually produces ( Findings: No blocking or correctness issues.
Nothing else to flag: minimal, single-purpose fix that reuses the existing whitelist mechanism, tests added to the existing suite rather than a new file, comment style and ASCII conventions respected. This review was generated automatically by pi coding agent using |
The bug
Three places disagree on the GBNF escape -:
How it drifted
Effect
A JSON Schema pattern containing - (e.g. ^[A-Za-z0-9_-]+$, ISO dates, phone/uuid shapes) hits unsupported_pattern, so the whole pattern silently falls back to the unconstrained string rule. It's a warning, not an error — easy to miss.
Repro: schema {"type":"string","pattern":"^[a-z\-]+$"} →
pattern ^[a-z-]+$ is not supported (unsupported escape in character class: -), accepting any string
The fix
One case '-': label in gbnf_escape_length(), plus a comment pointing at parse_char(). Two regression tests added. One pre-existing test that used ^[a-z-]+$ as "some unsupported pattern" was switched to a lookahead ^(?=a)a$ (no GBNF equivalent, so it can't silently stop testing anything if this bug class resurfaces).
Verification
Without the fix, with the new tests: exit 134 (assert abort). With the fix: exit 0. test-json-schema-to-grammar, test-grammar-parser, test-grammar-integration, test-chat all pass.