Skip to content

Fix IndexError in DateTimeParser.parse on malformed format strings - #1335

Open
aldorizona10-glitch wants to merge 1 commit into
arrow-py:masterfrom
aldorizona10-glitch:fix/parser-indexerror-1191
Open

Fix IndexError in DateTimeParser.parse on malformed format strings#1335
aldorizona10-glitch wants to merge 1 commit into
arrow-py:masterfrom
aldorizona10-glitch:fix/parser-indexerror-1191

Conversation

@aldorizona10-glitch

Copy link
Copy Markdown

Fixes #1191.

Problem

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.

Minimal reproducer (the report's fuzzed PoC reduces to this):

from arrow.parser import DateTimeParser
DateTimeParser().parse("foo", "[|(\\]s")   # IndexError: no such group

Fix

Guard the group lookup in parse() so a missing group raises ParserMatchError — matching the handling already used a few lines below when a matched group's value is None. 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, and isort are 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.rst entry referencing this PR once it has a number.

@codecov

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (2224255) to head (0981b88).

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.
📢 Have feedback on the report? Share it here.

@aldorizona10-glitch

Copy link
Copy Markdown
Author

Heads-up for reviewers: the one red check — windows-latest / pypy-3.11 — failed during environment setup, not in the tests. pip hit a transient network error building pyyaml's build dependencies (Connection broken: IncompleteRead), so tox never reached the suite. All other 26 checks pass, including ubuntu-latest / pypy-3.11 and codecov (100%). A re-run should clear it — happy to push a trivial change to re-trigger if that's easier.

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
@aldorizona10-glitch
aldorizona10-glitch force-pushed the fix/parser-indexerror-1191 branch from 4a881c4 to 0981b88 Compare August 9, 2026 02:58
@aldorizona10-glitch

Copy link
Copy Markdown
Author

Correction to my earlier note: a re-run did not clear it — and it turns out windows-latest / pypy-3.11 fails the same way on master and on the other current open PRs (#1330#1334), all with pip failing to build pyyaml's dependencies on that runner. So it's a pre-existing, environment-wide CI issue rather than anything specific to this change, which is green on all 26 other checks (codecov 100%). Flagging in case the required-check config needs a look on your side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IndexError in DateTimeParser.parse

1 participant