bpo-36239: Skip comments in gettext infos (GH-12255)

This commit is contained in:
Julien Palard 2019-05-09 16:22:15 +02:00 committed by GitHub
parent 88db8bd064
commit afd1e6d2f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 0 deletions

View File

@ -417,6 +417,9 @@ class GNUTranslations(NullTranslations):
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)

View File

@ -684,6 +684,19 @@ class GNUTranslationParsingTest(GettextBaseTest):
# 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):

View File

@ -0,0 +1 @@
Parsing .mo files now ignores comments starting and ending with #-#-#-#-#.