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[:1], date_time[-1:]) == ('"', '"'):
return date_time # Assume in correct format
else:
raise ValueError("date_time not of a known type")
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_imaplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ def test_Time2Internaldate_datetime_timetuple(self):
'"18-May-2033 05:33:20 +0200"',
)

def test_Time2Internaldate_invalid_str(self):
# gh-153854: an empty string raised IndexError instead of the
# documented ValueError.
for invalid in '', '18-May-2033 05:33:20 +0200':
with self.subTest(invalid=invalid):
with self.assertRaises(ValueError):
imaplib.Time2Internaldate(invalid)

def test_that_Time2Internaldate_returns_a_result(self):
# Without tzset, we can check only that it successfully
# produces a result, not the correctness of the result itself,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :func:`imaplib.Time2Internaldate` raising :exc:`IndexError` instead of
:exc:`ValueError` when passed an empty string.
Loading