]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Bug #1202493: Fixing SRE parser to handle '{}' as perl does, rather than
authorGeorg Brandl <georg@python.org>
Sun, 18 Sep 2005 13:03:16 +0000 (13:03 +0000)
committerGeorg Brandl <georg@python.org>
Sun, 18 Sep 2005 13:03:16 +0000 (13:03 +0000)
considering it exactly like a '*'.

Backport from 2.5 branch.

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

index 506661593740324f1822d6730f68902e411c546a..c8a2fa15acb44a79f6f531524dec9275e8e6a1ef 100644 (file)
@@ -474,6 +474,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 b0deaca8db4c9f29c2036043d894ef53fdc49af4..889f5f8906a97a968808288edb3d7bbdd454118c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -165,6 +165,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
 -----