Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
v4.27.0
=======

* Report a string as an invalid ``regex`` format rather than crashing when it contains a syntactically valid but oversized repetition count (which makes ``re.compile`` raise ``OverflowError`` instead of ``re.error``).

v4.26.0
=======

Expand Down
2 changes: 1 addition & 1 deletion jsonschema/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def is_time(instance: object) -> bool:
return is_datetime("1970-01-01T" + instance)


@_checks_drafts(name="regex", raises=re.error)
@_checks_drafts(name="regex", raises=(re.error, OverflowError))
def is_regex(instance: object) -> bool:
if not isinstance(instance, str):
return True
Expand Down
9 changes: 9 additions & 0 deletions jsonschema/tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ def test_format_checkers_come_with_defaults(self):
with self.assertRaises(FormatError):
checker.check(instance="not-an-ipv4", format="ipv4")

def test_regex_format_rejects_overflowing_repeat_count(self):
# A syntactically valid but oversized repetition count makes
# re.compile raise OverflowError, which is not an re.error, so it
# must be declared alongside it or it escapes uncaught instead of
# being reported as an invalid regex.
checker = FormatChecker()
with self.assertRaises(FormatError):
checker.check(instance="a{99999999999999}", format="regex")

def test_repr(self):
checker = FormatChecker(formats=())
checker.checks("foo")(lambda thing: True) # pragma: no cover
Expand Down