IndexError in DateTimeParser.parse

Open Beginner friendly
#1,191 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
65/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
python
Domain
backend

Research direction

Reproduce the failure with the DateTimeParser example in the issue and inspect arrow/parser.py around parse line 335, where match.group(token) raises IndexError. Compare the malformed fmt and regex match behavior, then verify that the reported input no longer produces this exception and that the resulting behavior is covered by the parser tests.

Written by the indexing model from the issue text.

Description

bug

The below code triggers a list index out of range error when provided a malformed input. This occurs in parse at line 335 in arrow/parser.py.
It seems that when the fmt string is malformed this can lead to a matching error in the regex parsing later in the function.

from arrow.parser import DateTimeParser
import sys

buf = open(sys.argv[1], "rb").read().decode("utf-8")
parser = DateTimeParser()
parser.parse("foo", buf)
Version

1.3.0

POC File

https://github.com/FuturesLab/POC/blob/main/arrow-py/poc-01

How to trigger

python filename.py poc-01

Trace Report
Traceback (most recent call last):
  File "rep.py", line 6, in <module>
    parser.parse("foo", buf)
  File "anon/lib/python3.8/site-packages/arrow/parser.py", line 331, in parse
    value = match.group(token)
IndexError: no such group
Dominant language
Python
Stars
9.1k
Forks
790
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from arrow-py/arrow

All issues in arrow-py/arrow

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.