From: Georg Brandl Date: Sun, 18 Sep 2005 13:03:16 +0000 (+0000) Subject: Bug #1202493: Fixing SRE parser to handle '{}' as perl does, rather than X-Git-Tag: v2.4.2c1~12 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=539604146aa5e33a5a1517f1a5fb4548153d77ef;p=thirdparty%2FPython%2Fcpython.git Bug #1202493: Fixing SRE parser to handle '{}' as perl does, rather than considering it exactly like a '*'. Backport from 2.5 branch. --- diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py index 506661593740..c8a2fa15acb4 100644 --- a/Lib/sre_parse.py +++ b/Lib/sre_parse.py @@ -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 = "" diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index eab995de6e65..9755005f1104 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -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) diff --git a/Misc/NEWS b/Misc/NEWS index b0deaca8db4c..889f5f8906a9 100644 --- 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 -----