Skip to content

bpo-36239: Skip comments in gettext infos #12255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Lib/gettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ def _parse(self, fp):
item = b_item.decode().strip()
if not item:
continue
# Skip over comment lines:
if item.startswith('#-#-#-#-#') and item.endswith('#-#-#-#-#'):
continue
k = v = None
if ':' in item:
k, v = item.split(':', 1)
Expand Down
13 changes: 13 additions & 0 deletions Lib/test/test_gettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,19 @@ def test_plural_form_error_issue17898(self):
# If this runs cleanly, the bug is fixed.
t = gettext.GNUTranslations(fp)

def test_ignore_comments_in_headers_issue36239(self):
"""Checks that comments like:

#-#-#-#-# messages.po (EdX Studio) #-#-#-#-#

are ignored.
"""
with open(MOFILE, 'wb') as fp:
fp.write(base64.decodebytes(GNU_MO_DATA_ISSUE_17898))
with open(MOFILE, 'rb') as fp:
t = gettext.GNUTranslations(fp)
self.assertEqual(t.info()["plural-forms"], "nplurals=2; plural=(n != 1);")


class UnicodeTranslationsTest(GettextBaseTest):
def setUp(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Parsing .mo files now ignores comments starting and ending with #-#-#-#-#.