Author itchyny
Recipients itchyny
Date 2021-02-22.13:58:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1614002299.86.0.551520528109.issue43295@roundup.psfhosted.org>
In-reply-to
Content
In Python 3.9.2, parsing 'z' (small letter) as '%z' (time zone offset) using datetime.strptime emits an IndexError.

>>> from datetime import datetime
>>> datetime.strptime('z', '%z')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/_strptime.py", line 568, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
  File "/usr/local/lib/python3.9/_strptime.py", line 453, in _strptime
    if z[3] == ':':
IndexError: string index out of range

I expect ValueError (or some another useful error) as follows.
ValueError: time data 'z' does not match format '%z'

This is caused by compiling '%z' to a pattern containing 'Z' (for UTC) with the IGNORECASE flag and accessing z[3] without noticing 'z' is accepted by the regexp.
History
Date User Action Args
2021-02-22 13:58:19itchynysetrecipients: + itchyny
2021-02-22 13:58:19itchynysetmessageid: <1614002299.86.0.551520528109.issue43295@roundup.psfhosted.org>
2021-02-22 13:58:19itchynylinkissue43295 messages
2021-02-22 13:58:19itchynycreate