Skip to content

Report regex compile failures as invalid format, not crashes. - #1

Merged
Anusha0501 merged 1 commit into
mainfrom
fix/1558-regex-format-uncaught-exceptions
Sep 10, 2026
Merged

Anusha0501 merged 1 commit into
mainfrom
fix/1558-regex-format-uncaught-exceptions

Conversation

@Anusha0501

Copy link
Copy Markdown
Owner

Summary

The regex format checker only treated re.error as an invalid instance. re.compile can also raise:

  • ValueError for conflicting inline flags such as (?u)(?a) (#1558)
  • RecursionError for deeply nested patterns (#1538)
  • OverflowError for oversized repeat counts (#1526)

Those exceptions escaped uncaught and crashed validation instead of reporting the string as an invalid regex.

This change declares those extra exception types on is_regex, matching other format checkers that already pass an exception tuple.

Fixes python-jsonschema#1538
Fixes python-jsonschema#1558

Test plan

  • Added regression tests in jsonschema/tests/test_format.py for unterminated patterns, conflicting flags, deep nesting, oversized repeats, and a valid pattern
  • uv run --group test python -m virtue jsonschema.tests.test_format
  • uv run --group test python -m virtue jsonschema

re.compile can raise ValueError, RecursionError, or OverflowError in
addition to re.error; catch those so the regex format checker reports
the instance as invalid instead of escaping uncaught.

Fixes python-jsonschema#1538
Fixes python-jsonschema#1558
@Anusha0501
Anusha0501 merged commit ad841b7 into main Sep 10, 2026
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.

regex format checker crashes with ValueError on conflicting inline flags regex format checker crashes with RecursionError on deeply nested patterns

1 participant