Conversation
Fixes python-babel#1219. Some tools (e.g. Poedit) leave these headers blank instead of eliding them or using the 'YEAR-MO-DA HO:MI+ZONE' placeholder. _parse_datetime_header() passed the blank value straight to datetime.strptime(), raising ValueError('time data '' does not match format...') and crashing pybabel on any such file, as reported. Treat a blank (or whitespace-only) value the same as an unset header: return None, matching the existing precedent a few lines up for the Language header ('if the header's value is an empty string, which is what some tools generate').
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.
Fixes #1219.
Bug
Some tools (e.g. Poedit) leave
PO-Revision-DateorPOT-Creation-Dateblank in a.pofile's header, instead of eliding the header or using theYEAR-MO-DA HO:MI+ZONEplaceholder._parse_datetime_header()passes that blank value straight todatetime.strptime(), which crashes:This takes down
pybabelentirely when updating or compiling such a file, as reported.Fix
Treat a blank (or whitespace-only) header value the same as an unset one: return
Noneinstead of raising. This matches the existing precedent a few lines up in the same function for theLanguageheader ("if the header's value is an empty string, which is what some tools generate").Test plan
test_datetime_parsing_blank_value_returns_none, parametrized over''and' '.read_po()on a.pofile with blankPO-Revision-Date/POT-Creation-Dateheaders, confirmed it's gone after the fix (both attributes becomeNone).pytest tests/messages/test_catalog.py— 21 passed (up from 19), same 25 pre-existing failures unrelated to this change (missing CLDR data files in this source checkout —RuntimeError: The babel data files are not available, identical failure list with and without this fix).ruff check/ruff format --checkclean on the changed lines.