Fix IndexError in DateTimeParser.parse on malformed format strings - #1335
Fix IndexError in DateTimeParser.parse on malformed format strings#1335aldorizona10-glitch wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1335 +/- ##
=========================================
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 Harness. |
|
Heads-up for reviewers: the one red check — |
A malformed format string can leave a token in `fmt_tokens` without a corresponding capture group in the compiled pattern (the bracket/escape reinsertion in `_generate_pattern_re` can desync the two). `parse()` then called `match.group(token)`, which raised a raw `IndexError: no such group` instead of Arrow's documented `ParserMatchError`. Guard the group lookup so a missing group raises `ParserMatchError`, matching the behaviour already used a few lines below when a group value is `None`. Adds a regression test using a minimal trigger derived from the report's PoC. Fixes arrow-py#1191
4a881c4 to
0981b88
Compare
|
Correction to my earlier note: a re-run did not clear it — and it turns out |
Fixes #1191.
Problem
A malformed format string can leave a token in
fmt_tokenswithout a corresponding capture group in the compiled pattern (the bracket/escape reinsertion in_generate_pattern_recan desync the two).parse()then calledmatch.group(token), which raised a rawIndexError: no such groupinstead of Arrow's documentedParserMatchError.Minimal reproducer (the report's fuzzed PoC reduces to this):
Fix
Guard the group lookup in
parse()so a missing group raisesParserMatchError— matching the handling already used a few lines below when a matched group's value isNone.parse()already documents:raises ParserMatchError:, so this makes the behaviour consistent with the contract.Testing
Ran the parser suite locally: 724 passed, plus a new regression test (
test_parse_malformed_fmt_no_match_group).black,flake8, andisortare all clean.Implemented with AI assistance (Claude Code, Opus 4.8); I reviewed the change and verified it locally as described above. Happy to add a
CHANGELOG.rstentry referencing this PR once it has a number.