Ignore blank PO-Revision-Date/POT-Creation-Date header values - #1317
Open
agu2347 wants to merge 1 commit into
Open
Ignore blank PO-Revision-Date/POT-Creation-Date header values#1317agu2347 wants to merge 1 commit into
agu2347 wants to merge 1 commit into
Conversation
_parse_datetime_header() unconditionally passed the header value to datetime.strptime(), so a blank date (left empty by tools such as Poedit instead of the conventional 'YEAR-MO-DA HO:MI+ZONE' placeholder or omitting the header) raised an unhandled ValueError, crashing `pybabel update`/`compile` while parsing an otherwise valid catalog. Make _parse_datetime_header() return None for a blank (or whitespace-only) value, and skip assigning creation_date/revision_date in that case instead of raising, matching the existing handling of the literal 'YEAR-MO-DA HO:MI+ZONE' placeholder for PO-Revision-Date. Fixes python-babel#1219
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pybabel update/compilecrashes with an unhandledValueErrorwhen a.pofile has a blankPO-Revision-Date(orPOT-Creation-Date) header value, as generated by some tools (e.g. Poedit) instead of the conventionalYEAR-MO-DA HO:MI+ZONEplaceholder or omitting the header entirely.Root cause
_parse_datetime_header()unconditionally passes its input todatetime.strptime(). Thepo-revision-datecall site already special-cases the literal'YEAR-MO-DA HO:MI+ZONE'placeholder to avoid parsing it, but doesn't handle a blank value, and thepot-creation-datecall site has no such guard at all.Fix
_parse_datetime_header()now returnsNonefor a blank (or whitespace-only) value instead of raising. Both call sites inCatalog._set_mime_headers()only assigncreation_date/revision_datewhen the parse actually returns a value, so a blank header now falls back to the existing defaults instead of crashing -- the same behavior the'YEAR-MO-DA HO:MI+ZONE'placeholder already gets.Testing
test_datetime_parsing_blank_value(unit test for_parse_datetime_header) andtest_set_mime_headers_ignores_blank_dates(integration test throughCatalog._set_mime_headers) totests/messages/test_catalog.py.tests/messages/test_catalog.py: 46 passed.tests/messages/(full, with CLDR data built viascripts/download_import_cldr.py): 383 passed, 1 skipped (the 3 apparent failures without CLDR/cwd setup are pre-existing and unrelated -- they pass once run from the repo root).babel/messages/catalog.py(keeping the new tests) reproduces the exact reported error:ValueError: time data '' does not match format '%Y-%m-%d %H:%M'.ruff checkclean on both changed files.Fixes #1219