Message402140
In going through some standard library code, I found that the email.utils.parsedate_tz() function (https://docs.python.org/3/library/email.utils.html#email.utils.parsedate_tz) has a bug if the time value is in dotted format and has more than 2 dots in it, for example: "12.34.56.78". Per the docs, it should return None in the case of invalid input.
This is happening because in the case that handles the '.' separator (instead of the normal ':'), there's no else clause to return None when there's not 2 or 3 segments.
From https://github.com/python/cpython/blob/dea59cf88adf5d20812edda330e085a4695baba4/Lib/email/_parseaddr.py#L118-L132:
if len(tm) == 2:
[thh, tmm] = tm
tss = '0'
elif len(tm) == 3:
[thh, tmm, tss] = tm
elif len(tm) == 1 and '.' in tm[0]:
# Some non-compliant MUAs use '.' to separate time elements.
tm = tm[0].split('.')
if len(tm) == 2:
[thh, tmm] = tm
tss = 0
elif len(tm) == 3:
[thh, tmm, tss] = tm
# HERE: need "else: return None"
else:
return None
We simply need to include that additional "else: return None" block in the '.' handling case.
I'll submit a pull request that fixes this soon (and adds a test for this case). |
|
Date |
User |
Action |
Args |
2021-09-18 22:35:53 | benhoyt | set | recipients:
+ benhoyt, barry |
2021-09-18 22:35:53 | benhoyt | set | messageid: <1632004553.3.0.0473045390855.issue45239@roundup.psfhosted.org> |
2021-09-18 22:35:53 | benhoyt | link | issue45239 messages |
2021-09-18 22:35:53 | benhoyt | create | |
|