]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #2537: Remove breaked check which prevented valid regular expressions.
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 19 Aug 2013 20:18:23 +0000 (23:18 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Mon, 19 Aug 2013 20:18:23 +0000 (23:18 +0300)
Patch by Meador Inge.

See also issue #18647.

Lib/sre_compile.py
Lib/test/test_re.py

index 40d2d520eda2907b0bb0d93721cf8fae6fafb29b..9f59c770dc49f3b57a852daf22a798f23bc97ff6 100644 (file)
@@ -358,8 +358,6 @@ def _optimize_unicode(charset, fixup):
 def _simple(av):
     # check if av is a "simple" operator
     lo, hi = av[2].getwidth()
-    #if lo == 0 and hi == MAXREPEAT:
-    #    raise error("nothing to repeat")
     return lo == hi == 1 and av[2][0][0] != SUBPATTERN
 
 def _compile_info(code, pattern, flags):
index c84d4edeb452f3fc189d074873370fc6d0a27586..2104437408df89fb46fdb7769bf80c65df85dc44 100644 (file)
@@ -1051,6 +1051,16 @@ class ReTests(unittest.TestCase):
                                  [b'xyz'], msg=pattern)
 
 
+    def test_bug_2537(self):
+        # issue 2537: empty submatches
+        for outer_op in ('{0,}', '*', '+', '{1,187}'):
+            for inner_op in ('{0,}', '*', '?'):
+                r = re.compile("^((x|y)%s)%s" % (inner_op, outer_op))
+                m = r.match("xyyzy")
+                self.assertEqual(m.group(0), "xyy")
+                self.assertEqual(m.group(1), "")
+                self.assertEqual(m.group(2), "y")
+
 def run_re_tests():
     from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR
     if verbose: