mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
[3.13] gh-130959: Reject whitespace in fractions, in pure Python fromisoformat()
(#130962) (#131076)
gh-130959: Reject whitespace in fractions, in pure Python `fromisoformat()` (#130962)
Fix the pure Python implementation of `fromisoformat()` to reject any
non-digit characters, including whitespace, in the fractional part
of time specification. This makes the behavior consistent with the C
implementation, and prevents incorrect parsing of these fractions
(e.g. `.400 ` would be misinterpreted as `.04`).
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Paul Ganssle <1377457+pganssle@users.noreply.github.com>
(cherry picked from commit 33494b4d0d
)
Co-authored-by: Michał Górny <mgorny@gentoo.org>
This commit is contained in:
parent
68a1591bec
commit
27fd328cf6
3 changed files with 11 additions and 3 deletions
|
@ -402,6 +402,8 @@ def _parse_hh_mm_ss_ff(tstr):
|
|||
raise ValueError("Invalid microsecond component")
|
||||
else:
|
||||
pos += 1
|
||||
if not all(map(_is_ascii_digit, tstr[pos:])):
|
||||
raise ValueError("Non-digit values in fraction")
|
||||
|
||||
len_remainder = len_str - pos
|
||||
|
||||
|
@ -413,9 +415,6 @@ def _parse_hh_mm_ss_ff(tstr):
|
|||
time_comps[3] = int(tstr[pos:(pos+to_parse)])
|
||||
if to_parse < 6:
|
||||
time_comps[3] *= _FRACTION_CORRECTION[to_parse-1]
|
||||
if (len_remainder > to_parse
|
||||
and not all(map(_is_ascii_digit, tstr[(pos+to_parse):]))):
|
||||
raise ValueError("Non-digit values in unparsed fraction")
|
||||
|
||||
return time_comps
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue