[Python-checkins] bpo-36239: Skip comments in gettext infos (GH-12255)
Julien Palard
webhook-mailer at python.org
Thu May 9 10:22:34 EDT 2019
https://github.com/python/cpython/commit/afd1e6d2f0f5aaf4030d13342809ec0915dedf81
commit: afd1e6d2f0f5aaf4030d13342809ec0915dedf81
branch: master
author: Julien Palard <julien at palard.fr>
committer: GitHub <noreply at github.com>
date: 2019年05月09日T16:22:15+02:00
summary:
bpo-36239: Skip comments in gettext infos (GH-12255)
files:
A Misc/NEWS.d/next/Library/2019-03-09-23-51-27.bpo-36239.BHJ3Ln.rst
M Lib/gettext.py
M Lib/test/test_gettext.py
diff --git a/Lib/gettext.py b/Lib/gettext.py
index 72a313a08562..b98f501884b7 100644
--- a/Lib/gettext.py
+++ b/Lib/gettext.py
@@ -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)
diff --git a/Lib/test/test_gettext.py b/Lib/test/test_gettext.py
index 8c0250eea1e7..9d1a96b8b0d1 100644
--- a/Lib/test/test_gettext.py
+++ b/Lib/test/test_gettext.py
@@ -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):
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
index 000000000000..3a7420291513
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-03-09-23-51-27.bpo-36239.BHJ3Ln.rst
@@ -0,0 +1 @@
+Parsing .mo files now ignores comments starting and ending with #-#-#-#-#.
More information about the Python-checkins
mailing list