-
-
Notifications
You must be signed in to change notification settings - Fork 34.8k
gh-151221: Fix plistlib loading of partial ISO 8601 dates #151217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -938,6 +938,24 @@ def test_load_aware_datetime(self): | |
| aware_datetime=True) | ||
| self.assertEqual(dt.tzinfo, datetime.UTC) | ||
|
|
||
| def test_load_partial_datetime(self): | ||
| # Smaller units may be omitted; missing components default to the | ||
| # start of the period. | ||
| for data, expected in [ | ||
| (b"<plist><date>2024Z</date></plist>", | ||
| datetime.datetime(2024, 1, 1)), | ||
| (b"<plist><date>2024-06Z</date></plist>", | ||
| datetime.datetime(2024, 6, 1)), | ||
| (b"<plist><date>2024-06-07Z</date></plist>", | ||
| datetime.datetime(2024, 6, 7)), | ||
| (b"<plist><date>2024-06-07T08Z</date></plist>", | ||
| datetime.datetime(2024, 6, 7, 8)), | ||
| (b"<plist><date>2024-06-07T08:09Z</date></plist>", | ||
| datetime.datetime(2024, 6, 7, 8, 9)), | ||
| ]: | ||
| with self.subTest(data=data): | ||
| self.assertEqual(plistlib.loads(data), expected) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this test also include one
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thankx for reviewing, but picnixz suggested I change the error type to ValueError instead of support it. Therefore, I’ve closed this PR. |
||
|
|
||
| @unittest.skipUnless("America/Los_Angeles" in zoneinfo.available_timezones(), | ||
| "Can't find timezone datebase") | ||
| def test_dump_aware_datetime(self): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Fix :mod:`plistlib` raising a confusing :exc:`TypeError` when loading a | ||
| ``<date>`` that omits smaller units (for example ``2024-06Z`` or ``2024Z``). | ||
| The omitted components now default to the start of the period. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if
2024Zis a valid ISO 8601 format. While year only (YYYY) format is ISO, I think timezone designators (in this case Zulu time) can only be attached to complete time value, not a standalone year.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, Z only belongs on a full time value, so 2024Z isn't strictly valid ISO 8601. Whether to accept partial dates at all is still being discussed in the issue. If accepted, I'll drop the Z from the examples.