Skip to content
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('#-#-#-#-#'):
Comment thread
JulienPalard marked this conversation as resolved.
Outdated
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);")
Comment thread
JulienPalard marked this conversation as resolved.
Outdated


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 #-#-#-#-#.