-
-
Notifications
You must be signed in to change notification settings - Fork 34.7k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-126845: Some edge cases in email.utils.parsedate_to_datetime seem to differ from RFC2822 spec #134438
Changes from all commits
a84d66c
df899ea
6112424
639514f
5dccaeb
83bdc71
1575dc3
3cba685
da6ff70
693bce3
87fef0c
9a40eed
5f589ba
19ed6c3
526cafd
67ded8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,6 +77,30 @@ def test_parsedate_to_datetime_with_invalid_raises_valueerror(self): | |
| with self.subTest(dtstr=dtstr): | ||
| self.assertRaises(ValueError, utils.parsedate_to_datetime, dtstr) | ||
|
|
||
| def test_parsedate_to_datetime_year_edge_cases(self): | ||
| expectations = { | ||
| # Various short-year formats that get expanded | ||
| "Sat, 15 Aug 0001 23:12:09 +0500": "2001", | ||
| "Thu, 1 Sep 1 23:12:09 +0800": "2001", | ||
| "Thu, 7 Oct 123 23:12:09 +0500": "2023", | ||
| "Tue, 17 Nov 2026 12:12:09 +0500": "2026", | ||
| # RFC 5322 section 4.3 boundaries for 2-digit years | ||
| "Mon, 1 Jan 0 00:00:00 +0000": "2000", | ||
| "Mon, 1 Jan 68 00:00:00 +0000": "2068", | ||
| "Mon, 1 Jan 69 00:00:00 +0000": "1969", | ||
| "Mon, 1 Jan 99 00:00:00 +0000": "1999", | ||
| # 3-digit year boundary | ||
| "Mon, 1 Jan 999 00:00:00 +0000": "2899", | ||
|
Member
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. Why the result is not 999?
Member
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. Because the RFC says it should be interpreted by adding 1900, which is what the PR is going to fix. |
||
| # Pre-1900 four-digit year: illegal per RFC but we accept it | ||
| "Mon, 1 Jan 1000 00:00:00 +0000": "1000", | ||
| } | ||
| for input_string, expected_year in expectations.items(): | ||
| with self.subTest(input_string=input_string): | ||
| self.assertEqual( | ||
| str(utils.parsedate_to_datetime(input_string))[:4], | ||
| expected_year, | ||
| ) | ||
|
|
||
| class LocaltimeTests(unittest.TestCase): | ||
|
|
||
| def test_localtime_is_tz_aware_daylight_true(self): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Fixed the :mod:`email` module parsing of three digit dates to | ||
|
Member
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 only change is removing a comment and adding a test. I do not think this NEWS entry is still relevant.
Member
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. No, the PR got messed up by my using the web to try to resolve the merge conflict, It's current state does not represent its intent, and all should be clear once it gets straightened out. |
||
| conform to :rfc:`5322`: three digit dates were previously | ||
| turned in to non-conformant four digit dates with a | ||
| leading ``0``. Now, per the RFC section 4.3, ``1990`` is added | ||
| to such dates to form compliant four digit years. | ||
|
|
||
| Contributed by Gustaf Gyllensporre. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why removed this comment? It was accurate.