Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/imaplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2272,7 +2272,7 @@ def Time2Internaldate(date_time):
if date_time.tzinfo is None:
raise ValueError("date_time must be aware")
dt = date_time
elif isinstance(date_time, str) and (date_time[0],date_time[-1]) == ('"','"'):
elif isinstance(date_time, str) and date_time.startswith('"') and date_time.endswith('"'):
return date_time # Assume in correct format
else:
raise ValueError("date_time not of a known type")
Expand Down
14 changes: 14 additions & 0 deletions Lib/test/test_imaplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,20 @@ def test_that_Time2Internaldate_returns_a_result(self):
for t in self.timevalues():
imaplib.Time2Internaldate(t)

def test_Time2Internaldate_quoted_string_passthrough(self):
# An already double-quoted string is assumed to be in the
# correct format and returned unchanged.
quoted = '"18-May-2033 05:33:20 +0200"'
self.assertEqual(imaplib.Time2Internaldate(quoted), quoted)

def test_Time2Internaldate_bad_string(self):
# A string that is not double-quoted is not of a known type and
# must raise ValueError, including the empty string (gh-153854).
for value in ('', 'x', '"x', 'x"'):
with self.subTest(value=value):
with self.assertRaises(ValueError):
imaplib.Time2Internaldate(value)

@socket_helper.skip_if_tcp_blackhole
def test_imap4_host_default_value(self):
# Check whether the IMAP4_PORT is truly unavailable.
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -2008,6 +2008,7 @@ Wm. Keith van der Meulen
Eric N. Vander Weele
Andrew Vant
Atul Varma
Vyron Vasileiadis
Dmitry Vasiliev
Sebastian Ortiz Vasquez
Alexandre Vassalotti
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:func:`imaplib.Time2Internaldate` now raises :exc:`ValueError` instead of
:exc:`IndexError` when passed an empty string, consistent with its documented
behaviour for strings that are not of a known type.
Loading