Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.3k
gh-126845: Some edge cases in email.utils.parsedate_to_datetime seem to differ from RFC2822 spec#134438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
gh-126845: Some edge cases in email.utils.parsedate_to_datetime seem to differ from RFC2822 spec#134438
Changes fromall commits
a84d66c
df899ea
6112424
639514f
5dccaeb
83bdc71
1575dc3
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -149,7 +149,7 @@ def _parsedate_tz(data): | ||
# calls for a two-digit yy, but RFC 2822 (which obsoletes RFC 822) | ||
# mandates a 4-digit yy. For more information, see the documentation for | ||
# the time module. | ||
iflen(str(yy)) >= 2 andyy < 100: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more.
| ||
# The year is between 1969 and 1999 (inclusive). | ||
if yy > 68: | ||
yy += 1900 | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -3227,7 +3227,7 @@ def test_parsedate_y2k(self): | ||
""" | ||
self.assertEqual(utils.parsedate_tz('25 Feb 03 13:47:26 -0800'), | ||
utils.parsedate_tz('25 Feb3 13:47:26 -0800')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. This makes the test ineffective. | ||
self.assertEqual(utils.parsedate_tz('25 Feb 71 13:47:26 -0800'), | ||
utils.parsedate_tz('25 Feb 1971 13:47:26 -0800')) | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Test to see if parsedate_to_datetime returns the correct year for different digit numbers, adhering to the RFC2822 spec | ||
import unittest | ||
from email.utils import parsedate_to_datetime | ||
class ParsedateToDatetimeTest(unittest.TestCase): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. parsedate_to_datetime tests belong in test_utils in DateTimeTests. (Those tests could maybe use some refactoring, but let's ignore that ;) | ||
def test(self): | ||
expectations = { | ||
"Sat, 15 Aug 0001 23:12:09 +0500": "0001", | ||
"Thu, 1 Sep 1 23:12:09 +0800": "0001", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Logically when doing a Postel "be generous in what you accept" recovery here, a single digit year should be treated as if it were a two digit year, which means the result here should 2001, which is what the current code produces. | ||
"Thu, 7 Oct 123 23:12:09 +0500": "0123", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. And this result should be 2023, per the rfc text you quoted (three digit years get 1900 added). I have no idea why that settled on that logic, it makes no sense to me, but that's what the RFC says. | ||
} | ||
for input_string, output_string in expectations.items(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. subTest would be good here. | ||
self.assertEqual(str(parsedate_to_datetime(input_string))[:4], output_string) | ||
if __name__ == '__main__': | ||
unittest.main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Fixed _parsedate_tz to not evaluate 1 digit years as as 4-digit years, adhering to RFC 2855 4.3 | ||
Contributed by Gustaf Gyllensporre. |
Uh oh!
There was an error while loading.Please reload this page.