Repository navigation
Conversation
re.compile raises ValueError (not an re.error subclass) when a pattern sets incompatible inline flags in separate groups, e.g. '(?u)(?a)'. The regex format checker declared raises=re.error only, so the ValueError escaped FormatChecker.check and crashed the caller instead of reporting the string as an invalid regex (python-jsonschema#1558). Declare ValueError alongside re.error. The single-group form (e.g. '(?ua)') already failed compilation with re.error and was reported correctly; only the two-group form escaped.
Documentation build overview
|
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1558.
Root cause
re.compileraisesValueError— which is not anre.errorsubclass — when a pattern sets incompatible inline flags in separate groups ("(?u)(?a)"or"(?a)(?u)"). Theregexformat checker declaredraises=re.erroronly, so the exception escapedFormatChecker.checkand crashed the caller instead of reporting the string as an invalid regex:The single-group form (
"(?ua)") fails compilation withre.errorand was already reported correctly; only the two-group form escaped.Fix
Declare
raises=(re.error, ValueError)onis_regex, so the conflicting-flagsValueErrorbecomes aFormatErrorwith the original exception as itscause, exactly like any other invalid regex.The related-but-distinct exception types from #1526 (
OverflowErroron an oversized repeat) and #1538 (RecursionErroron deep nesting) are left to their own issues — this PR only widens the declaration for theValueErrorfamily demonstrated in #1558.Test
test_regex_conflicting_inline_flags_report_invalid_not_errorinjsonschema/tests/test_format.py: both flag orders raiseFormatError/ conformFalse, the single-group form and a plainre.errorcase still report invalid, and a valid pattern still passes.Differential: the new test errors with the escaped
ValueErroronmainand passes with the change. Full suite:python -m unittest discover jsonschema.tests— 8455 tests, only a pre-existing localtest_exceptionsimport error unrelated to this change (also present on stashedmain).