From 1b65977025b67c9e030e7d69f904587c5a2ac332 Mon Sep 17 00:00:00 2001 From: Julien Palard Date: Sat, 9 Mar 2019 23:50:26 +0100 Subject: [PATCH 1/2] FIX: Skip comments in gettext infos. --- Lib/gettext.py | 2 ++ Lib/test/test_gettext.py | 7 +++++++ .../next/Library/2019-03-09-23-51-27.bpo-36239.BHJ3Ln.rst | 1 + 3 files changed, 10 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2019-03-09-23-51-27.bpo-36239.BHJ3Ln.rst diff --git a/Lib/gettext.py b/Lib/gettext.py index 72a313a0856262..c79cfb818e1834 100644 --- a/Lib/gettext.py +++ b/Lib/gettext.py @@ -417,6 +417,8 @@ def _parse(self, fp): item = b_item.decode().strip() if not item: continue + 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 8c0250eea1e789..6e1d5f8535b49e 100644 --- a/Lib/test/test_gettext.py +++ b/Lib/test/test_gettext.py @@ -684,6 +684,13 @@ 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): + 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 00000000000000..3a742029151378 --- /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 #-#-#-#-#. From b28003b32fc0d4422a13c7981ba4d5b56b49a594 Mon Sep 17 00:00:00 2001 From: Julien Palard Date: Wed, 8 May 2019 16:47:09 +0200 Subject: [PATCH 2/2] Add some comments. --- Lib/gettext.py | 1 + Lib/test/test_gettext.py | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/Lib/gettext.py b/Lib/gettext.py index c79cfb818e1834..b98f501884b75a 100644 --- a/Lib/gettext.py +++ b/Lib/gettext.py @@ -417,6 +417,7 @@ 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 diff --git a/Lib/test/test_gettext.py b/Lib/test/test_gettext.py index 6e1d5f8535b49e..9d1a96b8b0d1c8 100644 --- a/Lib/test/test_gettext.py +++ b/Lib/test/test_gettext.py @@ -685,6 +685,12 @@ def test_plural_form_error_issue17898(self): 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: