Skip to content

Escape null characters in generated pattern error messages - #226

Open
Doyoubelieveinfate wants to merge 1 commit into
horejsek:masterfrom
Doyoubelieveinfate:fix/null-character-pattern
Open

Doyoubelieveinfate wants to merge 1 commit into
horejsek:masterfrom
Doyoubelieveinfate:fix/null-character-pattern

Conversation

@Doyoubelieveinfate

Copy link
Copy Markdown

Compiling a valid schema containing a literal NUL in pattern raises SyntaxError: source code string cannot contain null bytes. This also affects character classes such as [\u0000-\u001f] and the source returned by compile_to_code.

Use the existing CodeGenerator.e() helper to escape the pattern in the generated exception message. Regex compilation and matching are unchanged. The new tests cover both patterns, both compilation APIs and both detailed-exception settings, including the successful match and the rejected value's error message.

Validation on macOS/Python 3.13.5:

  • All eight new cases fail before the change and pass afterward.
  • Full pytest -W default --benchmark-skip with the pinned JSON Schema Test Suite: 4,533 passed, 12 skipped, 445 xfailed and 940 xpassed; no failures.
  • Pylint reports warnings/refactoring suggestions on unchanged lines (9.90/10); no diagnostic on the changed line. git diff --check passes.
  • Reviewed generated-string escaping, preservation of the original pattern in exception messages, and coverage of both generated-code paths.

Prepared, tested and reviewed with Codex at the account owner's request.

This branch has not been deployed

No deployments
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.

1 participant