parse_date()\parse_time()\parse_datetime() fails on empty string or None object
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)
-
-
repo owner - changed status to resolved
-
repo owner Preparing a fix in 8.1.0.
None
and non-string parse arguments will now raiseValueError
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
, andparse_datetime
, will now raiseISOFormatError
.The changelog has a bit more detail.
-
repo owner 8.1.0 has been released and fixes this issue.
-
For what it’s worth, this broke code that was passing unicode on Python 2.7.
-
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. -
repo owner @Jean-Paul Calderone fixed in 8.1.1 (e9d5a0c specifically).
-
Nice, thank you.
- Log in to comment
I create a PR