fix: handle IndexError on malformed format strings in parser#1280
fix: handle IndexError on malformed format strings in parser#1280amanv0007 wants to merge 1 commit into
Conversation
- Catch IndexError during token group extraction and raise ParserMatchError instead. - Add test case for malformed format strings lacking expected regex named groups. - Fixes arrow-py#1191
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1280 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 10 10
Lines 2315 2318 +3
Branches 358 358
=========================================
+ Hits 2315 2318 +3 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Pull request overview
This PR hardens arrow.parser.DateTimeParser.parse() against malformed format strings that previously could trigger an uncaught IndexError during regex match-group extraction, converting that failure mode into a ParserMatchError and adding a regression test for the reported crash.
Changes:
- Wrap match-group extraction in
DateTimeParser.parse()with anIndexErrorhandler that raisesParserMatchError. - Add a regression test asserting malformed format strings raise
ParserMatchErrorinstead ofIndexError.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
arrow/parser.py |
Catches IndexError from match.group(...) during token extraction and re-raises ParserMatchError. |
tests/test_parser.py |
Adds a regression test covering the malformed-format-string crash scenario. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| f"Failed to match {fmt!r} when parsing {datetime_string!r}." | ||
| ) |
Pull Request Checklist
Thank you for taking the time to improve Arrow! Before submitting your pull request, please check all appropriate boxes:
toxormake testto find out!).tox -e lintormake lintto find out!).masterbranch.If you have any questions about your code changes or any of the points above, please submit your questions along with the pull request and we will try our best to help!
Description of Changes