| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
_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
|
You already opened a PR about the same thing earlier (#1293). |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
pybabel update/compile crashes with an unhandled ValueError when a .po file has a blank PO-Revision-Date (or POT-Creation-Date) header value, as generated by some tools (e.g. Poedit) instead of the conventional YEAR-MO-DA HO:MI+ZONE placeholder or omitting the header entirely.
File ".../babel/messages/catalog.py", line 109, in _parse_datetime_header dt = datetime.datetime.strptime(match.group('datetime'), '%Y-%m-%d %H:%M') ValueError: time data '' does not match format '%Y-%m-%d %H:%M'Root cause
_parse_datetime_header() unconditionally passes its input to datetime.strptime(). The po-revision-date call 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 the pot-creation-date call site has no such guard at all.
Fix
_parse_datetime_header() now returns None for a blank (or whitespace-only) value instead of raising. Both call sites in Catalog._set_mime_headers() only assign creation_date/revision_date when 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
Fixes #1219