Handle invalid plural index in msgstr[...] instead of raising ValueError (#1209) - #1279
Open
vineethsaivs wants to merge 1 commit into
Open
vineethsaivs wants to merge 1 commit into
vineethsaivs wants to merge 1 commit into
Conversation
vineethsaivs
force-pushed
the
fix/pofile-invalid-msgstr-index
branch
from
August 27, 2026 16:36
81d0a95 to
ccfa1d9
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1279 +/- ##
==========================================
+ Coverage 93.37% 93.41% +0.04%
==========================================
Files 27 27
Lines 4919 4924 +5
==========================================
+ Hits 4593 4600 +7
+ Misses 326 324 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…eError `int(idxarg[:-1])` on a keyword like `msgstr[\x0c]` raised a bare ValueError out of read_po. Report it through _invalid_pofile like every other malformed line, so abort_invalid=True raises PoFileError and the default path skips the entry with a warning. Leave in_msgstr off when the index is rejected: nothing was appended to self.translations, so a following continuation line would index an empty list. That is the same state the unknown-keyword path leaves the parser in, and the continuation then degrades to the existing "Got line starting with " but not in msgid, msgstr or msgctxt" warning.
vineethsaivs
force-pushed
the
fix/pofile-invalid-msgstr-index
branch
from
September 21, 2026 07:01
ccfa1d9 to
5707576
Compare
This branch has not been deployed
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 #1209.
read_poparses the plural index of amsgstr[N]line withint(idxarg[:-1]). WhenNis not an integer, this leaked a bareValueErrorto the caller:The fix routes a non-integer index through the parser's existing
_invalid_pofilehandling, so it raises aPoFileErrorwhenabort_invalid=Trueand otherwise warns and skips the line, consistent with how other malformed input is handled.in_msgstrstays off when the index is rejected. Nothing was appended toself.translations, so a continuation line after the bad keyword would index an empty list and raiseIndexError. This leaves the parser in the same state the unknown-keyword path does, and the continuation degrades to the existing warning.Two parametrized regression tests,
test_invalid_msgstr_index_issue_1209andtest_invalid_msgstr_index_continuation_issue_1209. All four cases fail onmasterand pass here. The rest oftests/messages/test_pofile.pyis 33 passed, with 4 pre-existing failures that need built CLDR data and fail the same way onmaster.Disclosure: prepared with AI assistance; reviewed by me and I can explain every line.