Skip to content

Commit 8d08764

Browse files
committed
plistlib: fix TypeError when parsing partial ISO 8601 dates
1 parent 3a8bebd commit 8d08764

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

Lib/plistlib.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,17 @@ def _date_from_string(s, aware_datetime):
143143
lst = []
144144
for key in order:
145145
val = gd[key]
146-
if val is None:
147-
break
148-
lst.append(int(val))
146+
if val is not None:
147+
lst.append(int(val))
148+
else:
149+
# Fill missing components with defaults: month/day -> 1, hour/minute/second -> 0
150+
if key in ('month', 'day'):
151+
lst.append(1)
152+
elif key in ('hour', 'minute', 'second'):
153+
lst.append(0)
154+
else:
155+
# Year should never be missing due to regex
156+
raise ValueError("Missing year in date string")
149157
if aware_datetime:
150158
return datetime.datetime(*lst, tzinfo=datetime.UTC)
151159
return datetime.datetime(*lst)

0 commit comments

Comments
 (0)