gh-126883: Add check that timezone fields are in range for `datetime.fromisoformat` by donbarbos · Pull Request #127242 · python/cpython · GitHub
Skip to content
Merged
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
44 changes: 35 additions & 9 deletions Lib/_pydatetime.py
9 changes: 9 additions & 0 deletions Lib/test/datetimetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -3567,6 +3567,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+00:90:00', # Time zone field out from range
'2009-04-19T12:30:45+00:00:90', # Time zone field out from range
Comment thread
donbarbos marked this conversation as resolved.
'2009-04-19T12:30:45-00:90:00', # Time zone field out from range
'2009-04-19T12:30:45-00:00:90', # Time zone field out from range
]

for bad_str in bad_strs:
Expand Down Expand Up @@ -4791,6 +4795,11 @@ 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)
'24:00:00.000001', # Has non-zero microseconds on 24:00
'24:00:01.000000', # Has non-zero seconds on 24:00
'24:01:00.000000', # Has non-zero minutes on 24:00
'12:30:45+00:90:00', # Time zone field out from range
'12:30:45+00:00:90', # Time zone field out from range
]

for bad_str in bad_strs:
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,7 @@ Paul Moore
Ross Moore
Ben Morgan
Emily Morehouse
Semyon Moroz
Derek Morr
James A Morrison
Martin Morrison
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Add check that timezone fields are in range for
:meth:`datetime.datetime.fromisoformat` and
:meth:`datetime.time.fromisoformat`. Patch by Semyon Moroz.
15 changes: 15 additions & 0 deletions Modules/_datetimemodule.c