Skip to content
Closed
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
14 changes: 11 additions & 3 deletions Lib/plistlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,17 @@ def _date_from_string(s, aware_datetime):
lst = []
for key in order:
val = gd[key]
if val is None:
break
lst.append(int(val))
if val is not None:
lst.append(int(val))
else:
# Fill missing components with defaults: month/day -> 1, hour/minute/second -> 0
if key in ('month', 'day'):
lst.append(1)
elif key in ('hour', 'minute', 'second'):
lst.append(0)
else:
# Year should never be missing due to regex
raise ValueError("Missing year in date string")
if aware_datetime:
return datetime.datetime(*lst, tzinfo=datetime.UTC)
return datetime.datetime(*lst)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
plistlib._date_from_string() was raising a confusing TypeError for partial ISO 8601 dates (e.g., '2024-06Z') because it broke early on missing components. The fix fills missing components with sensible defaults: month/day → 1, hour/minute/second → 0.
Loading