Skip to content

Commit 9e75bfe

Browse files
committed
Disallow : as microsecond separator for both implementations
1 parent 9dbe910 commit 9e75bfe

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

Lib/_pydatetime.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ def _parse_isoformat_date(dtstr):
404404

405405

406406
def _parse_hh_mm_ss_ff(tstr):
407-
# Parses things of the form HH[:?MM[:?SS[{.,:}fff[fff]]]]
407+
# Parses things of the form HH[:?MM[:?SS[{.,}fff[fff]]]]
408408
len_str = len(tstr)
409409

410410
time_comps = [0, 0, 0, 0]
@@ -430,7 +430,7 @@ def _parse_hh_mm_ss_ff(tstr):
430430
pos += has_sep
431431

432432
if pos < len_str:
433-
if tstr[pos] not in '.,:':
433+
if tstr[pos] not in '.,':
434434
raise ValueError("Invalid microsecond separator")
435435
else:
436436
pos += 1

Lib/test/datetimetester.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3534,6 +3534,7 @@ def test_fromisoformat_fails_datetime(self):
35343534
'2009-13-01T24:00:00.000000', # Month is invalid before wrapping due to 24:00
35353535
'9999-12-31T24:00:00.000000', # Year is invalid after wrapping due to 24:00
35363536
'2009-04-19T12:30Z12:00', # Extra time zone info after Z
3537+
'2009-04-19T12:30:45:334034', # Invalid microsecond separator
35373538
]
35383539

35393540
for bad_str in bad_strs:
@@ -4660,7 +4661,6 @@ def test_fromisoformat_time_examples(self):
46604661
('000000.000000', self.theclass(0, 0)),
46614662
('00:00:00.000000', self.theclass(0, 0)),
46624663
('00:00:00,100000', self.theclass(0, 0, 0, 100000)),
4663-
('00:00:00:100000', self.theclass(0, 0, 0, 100000)),
46644664
('1200', self.theclass(12, 0)),
46654665
('12:00', self.theclass(12, 0)),
46664666
('120000', self.theclass(12, 0)),
@@ -4729,6 +4729,7 @@ def test_fromisoformat_fails(self):
47294729
'12.5', # Decimal mark at end of hour
47304730
'12:30,5', # Decimal mark at end of minute
47314731
'12:30:45.123456Z12:00', # Extra time zone info after Z
4732+
'12:30:45:334034', # Invalid microsecond separator
47324733
]
47334734

47344735
for bad_str in bad_strs:

Modules/_datetimemodule.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,9 @@ parse_hh_mm_ss_ff(const char *tstr, const char *tstr_end, int *hour,
10141014
return c != '\0';
10151015
}
10161016
else if (has_separator && (c == ':')) {
1017+
if (i == 2) {
1018+
return -4; // Malformed microsecond separator
1019+
}
10171020
continue;
10181021
}
10191022
else if (c == '.' || c == ',') {

0 commit comments

Comments
 (0)