]> granicus.if.org Git - python/commitdiff
bpo-36239: Skip comments in gettext infos (GH-12255)
authorJulien Palard <julien@palard.fr>
Thu, 9 May 2019 14:22:15 +0000 (16:22 +0200)
committerGitHub <noreply@github.com>
Thu, 9 May 2019 14:22:15 +0000 (16:22 +0200)
Lib/gettext.py
Lib/test/test_gettext.py
Misc/NEWS.d/next/Library/2019-03-09-23-51-27.bpo-36239.BHJ3Ln.rst [new file with mode: 0644]

index 72a313a08562624c69fc57d69d52e7ca00edf01f..b98f501884b75a4e7d14ca124ad672938a99e541 100644 (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)
index 8c0250eea1e78900589f5eed3400cbce35a424a5..9d1a96b8b0d1c8c3d4f0e6a7e00da8251ab1f435 100644 (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):
diff --git a/Misc/NEWS.d/next/Library/2019-03-09-23-51-27.bpo-36239.BHJ3Ln.rst b/Misc/NEWS.d/next/Library/2019-03-09-23-51-27.bpo-36239.BHJ3Ln.rst
new file mode 100644 (file)
index 0000000..3a74202
--- /dev/null
@@ -0,0 +1 @@
+Parsing .mo files now ignores comments starting and ending with #-#-#-#-#.