gh-151221: Raise ValueError for invalid <date> in plistlib#153244
gh-151221: Raise ValueError for invalid <date> in plistlib#153244JavaZeroo wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8d928e31cd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| def _date_from_string(s, aware_datetime): | ||
| order = ('year', 'month', 'day', 'hour', 'minute', 'second') | ||
| gd = _dateParser.match(s).groupdict() | ||
| m = _dateParser.match(s) |
There was a problem hiding this comment.
Reject trailing content in XML date values
Using match() still accepts any value that merely starts with a valid plist timestamp, so inputs like <date>2024-01-01T00:00:00Zjunk</date> or <date>2024-01-01Z more</date> parse successfully instead of raising the newly documented ValueError for invalid <date> values. This leaves a class of malformed dates silently truncated; use a full-string match or anchor the regex so the whole element content is validated.
Useful? React with 👍 / 👎.
plistlib._date_from_string() raised a confusing TypeError (or an AttributeError for a completely non-matching value) when an XML <date> element held an invalid or partial ISO 8601 value such as "2024-06Z" or "2024Z". It now raises ValueError, consistent with the sibling <integer> and <real> elements. The binary plist format decodes dates with struct.unpack and is unaffected.
8d928e3 to
30ec8e8
Compare
Documentation build overview
|
|
Force push to rebase to the latest main branch and to fix the CI |
|
How is this different from #152958? |
|
Yes, sorry @JavaZeroo I'm closing in favour of the existing PR: https://github.com/python/cpython/pull/152958/changes |
plistlib._date_from_string()raised a confusing TypeError an AttributeError when an XML element held an invalid or partial ISO 8601 value such as "2024-06Z" or "2024Z". It now raises ValueError, consistent with the sibling and elements.plstlib: RaiseValueErrorinstead ofTypeErrorwhen loading a partial ISO 8601 date #151221