Skip to content
Draft
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
8 changes: 8 additions & 0 deletions Lib/test/datetimetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -3395,6 +3395,10 @@ def test_fromisoformat_fails_datetime(self):
'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)
'2009-04-19T12:30:45.+05:00', # Empty fraction before offset
'2009-04-19T12:30:45.-05:00', # Empty fraction before offset
'2009-04-19T12:30:45.Z', # Empty fraction before Z
'2009-04-19T12:30:45,+05:00', # Empty fraction (comma) before offset
]

for bad_str in bad_strs:
Expand Down Expand Up @@ -4508,6 +4512,10 @@ def test_fromisoformat_fails(self):
'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)
'12:30:45.+05:00', # Empty fraction before offset
'12:30:45.-05:00', # Empty fraction before offset
'12:30:45.Z', # Empty fraction before Z
'12:30:45,+05:00', # Empty fraction (comma) before offset
]

for bad_str in bad_strs:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The C implementations of :meth:`~datetime.datetime.fromisoformat` and :meth:`~datetime.time.fromisoformat`
now reject a decimal separator that is not followed by any
fractional digit before a timezone designator.
15 changes: 10 additions & 5 deletions Modules/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1013,17 +1013,22 @@ parse_hh_mm_ss_ff(const char *tstr, const char *tstr_end, int *hour,
has_separator = (c == ':');
}

if (p >= p_end) {
if (c == '.' || c == ',') {
if (p >= p_end) {
return -3; // Decimal mark not followed by any digit
}
break;
}
else if (p >= p_end) {
return c != '\0';
}
else if (has_separator && (c == ':')) {
continue;
}
else if (c == '.' || c == ',') {
break;
} else if (!has_separator) {
else if (!has_separator) {
--p;
} else {
}
else {
return -4; // Malformed time separator
}
}
Expand Down
Loading