FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.14] gh-152157: Reject empty fractions in `_datetime.{date}time.fromisoformat` (GH-152161) by tonghuaroot · Pull Request #152765 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) .rst  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
8 changes: 8 additions & 0 deletions Lib/test/datetimetester.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3582,6 +3582,10 @@ def test_fromisoformat_fails_datetime(self):
'2009-04-19T12:30:45.400 ', # Trailing space (gh-130959)
'2009-04-19T12:30:45. 400', # Space before fraction (gh-130959)
'2020-2020', # Ambiguous 9-char date portion
'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 @@ -4838,6 +4842,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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.
21 changes: 13 additions & 8 deletions Modules/_datetimemodule.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,16 @@ 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 (i < 2) {
return -3; // Decimal mark on hour or minute
}
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 == ':')) {
Expand All @@ -1040,14 +1049,10 @@ parse_hh_mm_ss_ff(const char *tstr, const char *tstr_end, int *hour,
}
continue;
}
else if (c == '.' || c == ',') {
if (i < 2) {
return -3; // Decimal mark on hour or minute
}
break;
} else if (!has_separator) {
else if (!has_separator) {
--p;
} else {
}
else {
return -4; // Malformed time separator
}
}
Expand Down
Loading

Back | FazBrowse Home | New Git URL