Skip to content

Wrong exception when parsing string with trailing or leading slash #506

Open
@fffaez

Description

@fffaez
  • I am on the latest Pendulum version.
    I have searched the issues of this repo and believe that this is not a duplicate.
  • OS version and name: Ubuntu 18.04.3 LTS
  • Pendulum version: 2.1.1

Issue

Parsing any string that begins or ends with a slash returns a IndexError instead of ValueError:

>>> from pendulum.parsing import parse
>>> parse("/2020")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ubuntu/pendulum/pendulum/parsing/__init__.py", line 74, in parse
    return _normalize(_parse(text, **_options), **_options)
  File "/home/ubuntu/pendulum/pendulum/parsing/__init__.py", line 115, in _parse
    return _parse_iso8601_interval(text)
  File "/home/ubuntu/pendulum/pendulum/parsing/__init__.py", line 221, in _parse_iso8601_interval
    if first[0] == "P":
IndexError: string index out of range

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @fffaez

      Issue actions

        Wrong exception when parsing string with trailing or leading slash · Issue #506 · python-pendulum/pendulum