bug 1344779, empty regex productions shouldn't be optional, r?flod draft
authorAxel Hecht <axel@pike.org>
Mon, 06 Mar 2017 18:00:06 +0100
changeset 175 842208369601e11998a51cecf55a427cf84f609c
parent 174 294692fffa33aec3abbee0323460cb411ec6b30e
push id39
push useraxel@mozilla.com
push dateMon, 06 Mar 2017 17:04:17 +0000
reviewersflod
bugs1344779
bug 1344779, empty regex productions shouldn't be optional, r?flod This replaces (\s*)? with (\s+)?, making the inner of the optional production non-empty. Added test to verify that .post content works as expected. MozReview-Commit-ID: 76hyoLJEdmq
compare_locales/parser.py
compare_locales/tests/test_dtd.py
--- a/compare_locales/parser.py
+++ b/compare_locales/parser.py
@@ -326,17 +326,17 @@ class DTDParser(Parser):
     # + \U00010000-\U000EFFFF seems to be unsupported in python
 
     # NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 |
     #     [#x0300-#x036F] | [#x203F-#x2040]
     NameChar = NameStartChar + ur'\-\.0-9' + u'\xB7\u0300-\u036F\u203F-\u2040'
     Name = '[' + NameStartChar + '][' + NameChar + ']*'
     reKey = re.compile('(?:(?P<pre>\s*)(?P<entity><!ENTITY\s+(?P<key>' + Name +
                        ')\s+(?P<val>\"[^\"]*\"|\'[^\']*\'?)\s*>)'
-                       '(?P<post>\s*)?)',
+                       '(?P<post>\s+)?)',
                        re.DOTALL | re.M)
     # add BOM to DTDs, details in bug 435002
     reHeader = re.compile(u'^\ufeff')
     reComment = re.compile('(\s*)(<!--(-?[%s])*?-->)(\s*)' % CharMinusDash,
                            re.S)
     rePE = re.compile(u'(?:(\s*)'
                       u'(<!ENTITY\s+%\s+(' + Name +
                       u')\s+SYSTEM\s+(\"[^\"]*\"|\'[^\']*\')\s*>\s*%' + Name +
--- a/compare_locales/tests/test_dtd.py
+++ b/compare_locales/tests/test_dtd.py
@@ -119,11 +119,19 @@ escaped value">
         self.assertEqual(one.position(), (1, 1))
         self.assertEqual(one.value_position(), (1, 16))
         self.assertEqual(one.position(-1), (2, 1))
         self.assertEqual(two.position(), (2, 1))
         self.assertEqual(two.value_position(), (2, 16))
         self.assertEqual(two.value_position(-1), (3, 14))
         self.assertEqual(two.value_position(10), (3, 5))
 
+    def test_post(self):
+        self.parser.readContents('<!ENTITY a "a"><!ENTITY b "b">')
+        a, b = list(self.parser)
+        self.assertEqual(a.post, '')
+        self.parser.readContents('<!ENTITY a "a"> <!ENTITY b "b">')
+        a, b = list(self.parser)
+        self.assertEqual(a.post, ' ')
+
 
 if __name__ == '__main__':
     unittest.main()