Fix #1794: Regexp/NotRegexp no longer panic on invalid regex#1857
Open
cobyfrombrooklyn-bot wants to merge 1 commit intostretchr:masterfrom
Open
Fix #1794: Regexp/NotRegexp no longer panic on invalid regex#1857cobyfrombrooklyn-bot wants to merge 1 commit intostretchr:masterfrom
cobyfrombrooklyn-bot wants to merge 1 commit intostretchr:masterfrom
Conversation
Use regexp.Compile instead of regexp.MustCompile in matchRegexp so invalid patterns cause a test failure with a clear error message instead of a runtime panic. Fixes stretchr#1794
Collaborator
|
Why opening almost same code than |
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 #1794
Problem
assert.Regexpandassert.NotRegexpuseregexp.MustCompileinternally, which panics on invalid regex patterns like\C. This causes a runtime panic instead of a test failure.Fix
Changed
matchRegexpto useregexp.Compileand return an error.RegexpandNotRegexpnow handle the error by callingFailwith a clear message likeInvalid regexp "\C": error parsing regexp: invalid escape sequence: \C.Test
Added
TestRegexpWithInvalidRegexthat passes invalid patterns (\Cand(?P<open>[)) to bothRegexpandNotRegexp. Without the fix, this test panics. With the fix, it passes (assertions return false with error messages).Tested locally on macOS ARM (Apple Silicon). Full test suite passes.