https://github.com/python/cpython/commit/14e3c7071bd1add30d4b69b62e011c7d38aebd9b
commit: 14e3c7071bd1add30d4b69b62e011c7d38aebd9b
branch: main
author: benchatt <[email protected]>
committer: pganssle <[email protected]>
date: 2024-06-05T13:35:40-04:00
summary:

gh-115225: Raise error on unsupported ISO 8601 time strings (#119339)

Some time strings that contain fractional hours or minutes are permitted
by ISO 8601, but such strings are very unlikely to be intentional. The
current parser does not parse such strings correctly or raise an error.
This change raises a ValueError when hours or minutes contain a decimal mark.

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>

files:
A Misc/NEWS.d/next/Library/2024-05-21-19-10-30.gh-issue-115225.eRmfJH.rst
M Lib/test/datetimetester.py
M Misc/ACKS
M Modules/_datetimemodule.c

diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
index 535b17d0727611..3759504b02e550 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -4412,6 +4412,8 @@ def test_fromisoformat_fails(self):
             '12:30:45.123456-',         # Extra at end of microsecond time
             '12:30:45.123456+',         # Extra at end of microsecond time
             '12:30:45.123456+12:00:30a',    # Extra at end of full time
+            '12.5',                     # Decimal mark at end of hour
+            '12:30,5',                  # Decimal mark at end of minute
         ]
 
         for bad_str in bad_strs:
diff --git a/Misc/ACKS b/Misc/ACKS
index 2e7e12481bacd7..af92d81ff3141a 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -315,6 +315,7 @@ Greg Chapman
 Mitch Chapman
 Matt Chaput
 William Chargin
+Ben Chatterton
 Yogesh Chaudhari
 Gautam Chaudhuri
 David Chaum
diff --git 
a/Misc/NEWS.d/next/Library/2024-05-21-19-10-30.gh-issue-115225.eRmfJH.rst 
b/Misc/NEWS.d/next/Library/2024-05-21-19-10-30.gh-issue-115225.eRmfJH.rst
new file mode 100644
index 00000000000000..2b65eaa6dd70ad
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-05-21-19-10-30.gh-issue-115225.eRmfJH.rst
@@ -0,0 +1 @@
+Raise error on certain technically valid but pathological ISO 8601 strings 
passed to :meth:`datetime.time.fromisoformat` that were previously parsed 
incorrectly.
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index d6fa273c75e15e..bea6e9411a75ed 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -1020,6 +1020,9 @@ 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) {
             --p;

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to