Skip to content

gh-151221: Raise ValueError for invalid <date> in plistlib#153244

Closed
JavaZeroo wants to merge 1 commit into
python:mainfrom
JavaZeroo:fix/plistlib-invalid-date-valueerror
Closed

gh-151221: Raise ValueError for invalid <date> in plistlib#153244
JavaZeroo wants to merge 1 commit into
python:mainfrom
JavaZeroo:fix/plistlib-invalid-date-valueerror

Conversation

@JavaZeroo

@JavaZeroo JavaZeroo commented Jul 7, 2026

Copy link
Copy Markdown

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread Lib/plistlib.py
def _date_from_string(s, aware_datetime):
order = ('year', 'month', 'day', 'hour', 'minute', 'second')
gd = _dateParser.match(s).groupdict()
m = _dateParser.match(s)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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.
@JavaZeroo JavaZeroo force-pushed the fix/plistlib-invalid-date-valueerror branch from 8d928e3 to 30ec8e8 Compare July 7, 2026 03:29
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33471535 | 📁 Comparing 30ec8e8 against main (35c6779)

  🔍 Preview build  

2 files changed
± library/plistlib.html
± whatsnew/changelog.html

@JavaZeroo

Copy link
Copy Markdown
Author

Force push to rebase to the latest main branch and to fix the CI

@AleksaMCode

Copy link
Copy Markdown

How is this different from #152958?

@StanFromIreland

Copy link
Copy Markdown
Member

Yes, sorry @JavaZeroo I'm closing in favour of the existing PR: https://github.com/python/cpython/pull/152958/changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants