Don't crash on blank PO-Revision-Date / POT-Creation-Date headers#1293
Open
agu2347 wants to merge 1 commit into
Open
Don't crash on blank PO-Revision-Date / POT-Creation-Date headers#1293agu2347 wants to merge 1 commit into
agu2347 wants to merge 1 commit into
Conversation
Some tools (e.g. Poedit) can leave the PO-Revision-Date header blank in a generated .po file instead of omitting it or using the conventional 'YEAR-MO-DA HO:MI+ZONE' placeholder. Parsing such a file crashed with: ValueError: time data '' does not match format '%Y-%m-%d %H:%M' because _parse_datetime_header() was called unconditionally with the blank value. Guard both call sites (po-revision-date and, for the same reason, pot-creation-date) to skip parsing when the header value is blank, keeping the previous/default value instead -- the same treatment already given to the 'YEAR-MO-DA HO:MI+ZONE' placeholder value just above, and to a blank Language header elsewhere in this same method. Added a regression test that parses a message block with both headers blank and asserts: no exception is raised, the catalog's creation_date/revision_date fall back to their defaults rather than being corrupted, and no literal 'None' leaks into the round-tripped mime_headers output. Confirmed the test fails with the original ValueError without the fix, and passes with it. Also verified end-to-end with an actual .po file parse + write round-trip (using an installed release build with CLDR data, since a shallow clone here can't build that data), and confirmed normal (non-blank) header values are completely unaffected. Ran the full existing test_catalog.py and test_pofile.py suites: all pass, no regressions. 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.
Fixes #1219.
Some tools (e.g. Poedit) can leave the
PO-Revision-Dateheader blank in a generated.pofile instead of omitting it or using the conventionalYEAR-MO-DA HO:MI+ZONEplaceholder. Parsing such a file crashes with:because
_parse_datetime_header()is called unconditionally with the blank value, as reported in the issue.Fix: guard both call sites (
po-revision-dateand, for the same reason,pot-creation-date) to skip parsing when the header value is blank, keeping the previous/default value instead -- the same treatment already given to theYEAR-MO-DA HO:MI+ZONEplaceholder value right above it, and to a blankLanguageheader elsewhere in this same method (self._set_locale(value or None)).Testing: added a regression test that parses a message block with both headers blank and asserts: no exception is raised,
creation_date/revision_datefall back to their defaults rather than being corrupted, and no literalNoneleaks into the round-trippedmime_headersoutput. I confirmed the test fails with the originalValueErrorwithout the fix, and passes with it.I also verified end-to-end with an actual
.pofile parse + write round-trip (using an installed release build with CLDR data, since a shallow clone here can't build that data on its own), confirming noNoneleaks into the output and that normal (non-blank) header values are completely unaffected. Ran the full existingtest_catalog.pyandtest_pofile.pysuites: all pass, no regressions.