Bug report
Bug description:
plistlib.loads() on an XML plist whose <date> element does not parse to a
datetime raises an internal AttributeError or TypeError instead of a
proper error. The sibling <integer> and <real> elements already raise
ValueError on malformed content, so a <date> should too.
_date_from_string (Lib/plistlib.py) does _dateParser.match(s).groupdict().
On a fully non-matching value match() returns None, so .groupdict() fails
with AttributeError. On a partial match (the regex allows year-only and
year-month), too few fields reach datetime.datetime(*lst), which fails with
TypeError.
import plistlib
plistlib.loads(b"<plist><date>not a date</date></plist>") # AttributeError
plistlib.loads(b"<plist><date>2004Z</date></plist>") # TypeError
The binary plist format is unaffected: it decodes dates with struct.unpack
and never uses this regex.
CPython versions tested on:
3.15 (main); the affected code is unchanged on 3.13 and 3.14.
Operating systems tested on:
Any (pure Python)
Linked PRs
Bug report
Bug description:
plistlib.loads()on an XML plist whose<date>element does not parse to adatetimeraises an internalAttributeErrororTypeErrorinstead of aproper error. The sibling
<integer>and<real>elements already raiseValueErroron malformed content, so a<date>should too._date_from_string(Lib/plistlib.py) does_dateParser.match(s).groupdict().On a fully non-matching value
match()returnsNone, so.groupdict()failswith
AttributeError. On a partial match (the regex allows year-only andyear-month), too few fields reach
datetime.datetime(*lst), which fails withTypeError.The binary plist format is unaffected: it decodes dates with
struct.unpackand never uses this regex.
CPython versions tested on:
3.15 (main); the affected code is unchanged on 3.13 and 3.14.
Operating systems tested on:
Any (pure Python)
Linked PRs