-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-30681: Support invalid date format or value in email Date header #10783
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
Changes from all commits
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 |
---|---|---|
|
@@ -46,6 +46,14 @@ def msg_as_input(self, msg): | |
foo | ||
"""),), | ||
|
||
'header_with_invalid_date': (dedent(b"""\ | ||
Date: Tue, 06 Jun 2017 27:39:33 +0600 | ||
From: [email protected] | ||
Subject: timezones | ||
|
||
How do they work even? | ||
"""),), | ||
|
||
} | ||
|
||
payload_params = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,22 @@ def test_parsedate_to_datetime_naive(self): | |
utils.parsedate_to_datetime(self.datestring + ' -0000'), | ||
self.naive_dt) | ||
|
||
def test_parsedate_to_datetime_with_invalid_raises_typeerror(self): | ||
with self.assertRaises(TypeError): | ||
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. I think this is fine as is, but I think it would be improved if you used a loop and subtests: invalid_dates = ['', '0', 'A Complete Waste of Time']
for dtstr in invalid_dates:
with self.subTest(dtstr=dtstr):
with self.assertRaises(TypeError):
utils.parsedate_to_datetime(dtstr) Obviously that's pretty nested (though you can probably cut out one layer of nesting by using Same comment also applies to the test for |
||
utils.parsedate_to_datetime('') | ||
with self.assertRaises(TypeError): | ||
utils.parsedate_to_datetime('0') | ||
with self.assertRaises(TypeError): | ||
utils.parsedate_to_datetime('A Complete Waste of Time') | ||
|
||
def test_parsedate_to_datetime_with_invalid_raises_valueerror(self): | ||
with self.assertRaises(ValueError): | ||
utils.parsedate_to_datetime('Tue, 06 Jun 2017 27:39:33 +0600') | ||
with self.assertRaises(ValueError): | ||
utils.parsedate_to_datetime('Tue, 06 Jun 2017 07:39:33 +2600') | ||
with self.assertRaises(ValueError): | ||
utils.parsedate_to_datetime('Tue, 06 Jun 2017 27:39:33') | ||
|
||
|
||
class LocaltimeTests(unittest.TestCase): | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Handle exceptions caused by unparseable date headers when using email | ||
"default" policy. Patch by Tim Bell. |
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.
Can you also please add this to documentation under
email.errors.rst
?