parse_date()\parse_time()\parse_datetime() fails on empty string or None object

Issue #26 resolved
Former user created an issue

Step to reproduce:

>>> import aniso8601
>>> aniso8601.parse_date("")

Actual behaviour:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pavel/PycharmProjects/the_delneg/croinc/croinc_backend_v2/venv/lib/python3.9/site-packages/aniso8601/date.py", line 110, in parse_date
    return _RESOLUTION_MAP[get_date_resolution(isodatestr)](isodatestr,
  File "/home/pavel/PycharmProjects/the_delneg/croinc/croinc_backend_v2/venv/lib/python3.9/site-packages/aniso8601/date.py", line 30, in get_date_resolution
    if isodatestr[0].isdigit() is False or isodatestr[-1].isdigit() is False:
IndexError: string index out of range

Expected behaviour: same as on wrong date string:

>>> aniso8601.parse_date("wrong date string")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pavel/PycharmProjects/the_delneg/croinc/croinc_backend_v2/venv/lib/python3.9/site-packages/aniso8601/date.py", line 110, in parse_date
    return _RESOLUTION_MAP[get_date_resolution(isodatestr)](isodatestr,
  File "/home/pavel/PycharmProjects/the_delneg/croinc/croinc_backend_v2/venv/lib/python3.9/site-packages/aniso8601/date.py", line 31, in get_date_resolution
    raise ISOFormatError('"{0}" is not a valid ISO 8601 date.'
aniso8601.exceptions.ISOFormatError: "wrong date string" is not a valid ISO 8601 date.

Comments (8)

  1. Brandon Nielsen repo owner

    Preparing a fix in 8.1.0.

    None and non-string parse arguments will now raise ValueError matching the behavior of Python 3.7’s fromisoformat.

    Empty (and some other “bad strings”) parse string arguments to get_date_resolution, parse_date, parse_duration, parse_interval, parse_repeating_interval, get_time_resolution, parse_time, and parse_datetime, will now raise ISOFormatError.

    The changelog has a bit more detail.

  2. Brandon Nielsen repo owner

    @Jean-Paul Calderone That is definitely an unwanted regression, track progress in #28, will hopefully be fixed with an 8.1.1 release relatively quickly.

  3. Log in to comment