fix IndexError in DateTimeParser.parse with malformed format strings#1243
Open
Mr-Neutr0n wants to merge 1 commit intoarrow-py:masterfrom
Open
fix IndexError in DateTimeParser.parse with malformed format strings#1243Mr-Neutr0n wants to merge 1 commit intoarrow-py:masterfrom
Mr-Neutr0n wants to merge 1 commit intoarrow-py:masterfrom
Conversation
when a malformed format string produces regex groups that don't match the extracted token list, match.group(token) raises IndexError instead of a proper ParserMatchError. catch IndexError in the token extraction loop and raise ParserMatchError instead. fixes arrow-py#1191
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1243 +/- ##
==========================================
Coverage ? 100.00%
==========================================
Files ? 10
Lines ? 2318
Branches ? 358
==========================================
Hits ? 2318
Misses ? 0
Partials ? 0 ☔ View full report in Codecov by Sentry. |
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.
Malformed format strings can cause
DateTimeParser.parse()to raise anIndexErrorinstead of aParserMatchError. This happens when the format string contains characters that, after regex escaping and bracket expression handling, produce a token list that doesn't align with the named groups in the generated regex pattern.match.group(token)then blows up withIndexError: no such group.The fix wraps the
match.group()calls in a try/except to catchIndexErrorand raiseParserMatchErrorinstead, which is the expected exception type for parse failures.Reproducer from #1191:
Added a regression test. All 723 existing parser tests still pass.
Fixes #1191