Skip to content
Closed
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
5 changes: 5 additions & 0 deletions Lib/test/datetimetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -3959,6 +3959,8 @@ def test_fromisoformat_fails_datetime(self):
'9999-12-31T24:00:00.000000', # Year is invalid after wrapping due to 24:00
'2009-04-19T12:30Z12:00', # Extra time zone info after Z
'2009-04-19T12:30:45:334034', # Invalid microsecond separator
'20090419T12304512', # Fraction without decimal mark (basic format)
'2009-04-19T12304512', # Fraction without decimal mark (basic format)
'2009-04-19T12:30:45.400 +02:30', # Space between ms and timezone (gh-130959)
'2009-04-19T12:30:45.400 ', # Trailing space (gh-130959)
'2009-04-19T12:30:45. 400', # Space before fraction (gh-130959)
Expand Down Expand Up @@ -5306,6 +5308,9 @@ def test_fromisoformat_fails(self):
'12:30,5', # Decimal mark at end of minute
'12:30:45.123456Z12:00', # Extra time zone info after Z
'12:30:45:334034', # Invalid microsecond separator
'12304512', # Fraction without decimal mark (basic format)
'123045123456', # Fraction without decimal mark (basic format)
'T12304512', # Fraction without decimal mark (basic format)
'12:30:45.400 +02:30', # Space between ms and timezone (gh-130959)
'12:30:45.400 ', # Trailing space (gh-130959)
'12:30:45. 400', # Space before fraction (gh-130959)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:meth:`datetime.time.fromisoformat` and
:meth:`datetime.datetime.fromisoformat` now reject digits after the seconds
of a time in the basic format when there is no decimal mark, such as
``"12304512"``. The C implementation previously read them as a fractional
second, while the pure-Python implementation rejected them.
3 changes: 3 additions & 0 deletions Modules/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,9 @@ parse_hh_mm_ss_ff(const char *tstr, const char *tstr_end, int *hour,
continue;
}
else if (!has_separator) {
if (i == 2) {
return -4; // Malformed microsecond separator
}
--p;
}
else {
Expand Down
Loading