]> granicus.if.org Git - python/commitdiff
Bug #1202493: Fixing SRE parser to handle '{}' as perl does, rather than
authorGustavo Niemeyer <gustavo@niemeyer.net>
Wed, 14 Sep 2005 08:54:39 +0000 (08:54 +0000)
committerGustavo Niemeyer <gustavo@niemeyer.net>
Wed, 14 Sep 2005 08:54:39 +0000 (08:54 +0000)
considering it exactly like a '*'.

Lib/sre_parse.py
Lib/test/test_re.py
Misc/NEWS

index 33b399ef654310c27f0fc0f5b715933e8619782f..319bf43b33f048d8f4528e876592f7ca7b71a591 100644 (file)
@@ -485,6 +485,9 @@ def _parse(source, state):
             elif this == "+":
                 min, max = 1, MAXREPEAT
             elif this == "{":
+                if source.next == "}":
+                    subpatternappend((LITERAL, ord(this)))
+                    continue
                 here = source.tell()
                 min, max = 0, MAXREPEAT
                 lo = hi = ""
index eab995de6e6565cdf0ca200793654a474607ba93..9755005f110437d1976ef99b6a1dd4b8ffa35805 100644 (file)
@@ -297,6 +297,9 @@ class ReTests(unittest.TestCase):
         self.assertNotEqual(re.match("^x{1,4}?$", "xxx"), None)
         self.assertNotEqual(re.match("^x{3,4}?$", "xxx"), None)
 
+        self.assertEqual(re.match("^x{}$", "xxx"), None)
+        self.assertNotEqual(re.match("^x{}$", "x{}"), None)
+
     def test_getattr(self):
         self.assertEqual(re.match("(a)", "a").pos, 0)
         self.assertEqual(re.match("(a)", "a").endpos, 1)
index 29f2b44ed745ffeef6887ef50444652235cb9233..27483d45a1b27d946d7aebdfb2bfbf750043e9ac 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -443,6 +443,10 @@ Library
   from the input stream, so that the output is a byte string in the correct
   encoding instead of a unicode string.
 
+- Bug #1202493: Fixing SRE parser to handle '{}' as perl does, rather than
+  considering it exactly like a '*'.
+
+
 Build
 -----