Blame SOURCES/00256-fix-incorrect-parsing-of-regular-expressions.patch

71084d
diff --git a/Lib/sre_compile.py b/Lib/sre_compile.py
71084d
index 7cda2b6..15d2324 100644
71084d
--- a/Lib/sre_compile.py
71084d
+++ b/Lib/sre_compile.py
71084d
@@ -355,8 +355,6 @@ def _optimize_unicode(charset, fixup):
71084d
 def _simple(av):
71084d
     # check if av is a "simple" operator
71084d
     lo, hi = av[2].getwidth()
71084d
-    if lo == 0 and hi == MAXREPEAT:
71084d
-        raise error, "nothing to repeat"
71084d
     return lo == hi == 1 and av[2][0][0] != SUBPATTERN
71084d
 
71084d
 def _compile_info(code, pattern, flags):
71084d
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py
71084d
index 75f8c96..644441d 100644
71084d
--- a/Lib/sre_parse.py
71084d
+++ b/Lib/sre_parse.py
71084d
@@ -147,7 +147,7 @@ class SubPattern:
71084d
         REPEATCODES = (MIN_REPEAT, MAX_REPEAT)
71084d
         for op, av in self.data:
71084d
             if op is BRANCH:
71084d
-                i = sys.maxint
71084d
+                i = MAXREPEAT - 1
71084d
                 j = 0
71084d
                 for av in av[1]:
71084d
                     l, h = av.getwidth()
71084d
@@ -165,14 +165,14 @@ class SubPattern:
71084d
                 hi = hi + j
71084d
             elif op in REPEATCODES:
71084d
                 i, j = av[2].getwidth()
71084d
-                lo = lo + long(i) * av[0]
71084d
-                hi = hi + long(j) * av[1]
71084d
+                lo = lo + i * av[0]
71084d
+                hi = hi + j * av[1]
71084d
             elif op in UNITCODES:
71084d
                 lo = lo + 1
71084d
                 hi = hi + 1
71084d
             elif op == SUCCESS:
71084d
                 break
71084d
-        self.width = int(min(lo, sys.maxint)), int(min(hi, sys.maxint))
71084d
+        self.width = min(lo, MAXREPEAT - 1), min(hi, MAXREPEAT)
71084d
         return self.width
71084d
 
71084d
 class Tokenizer:
71084d
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
71084d
index 18a81a2..f0827d8 100644
71084d
--- a/Lib/test/test_re.py
71084d
+++ b/Lib/test/test_re.py
71084d
@@ -897,6 +897,17 @@ class ReTests(unittest.TestCase):
71084d
         with self.assertRaisesRegexp(sre_constants.error, '\?foo'):
71084d
             re.compile('(?P)')
71084d
 
71084d
+    def test_bug_2537(self):
71084d
+        # issue 2537: empty submatches
71084d
+        for outer_op in ('{0,}', '*', '+', '{1,187}'):
71084d
+            for inner_op in ('{0,}', '*', '?'):
71084d
+                r = re.compile("^((x|y)%s)%s" % (inner_op, outer_op))
71084d
+                m = r.match("xyyzy")
71084d
+                self.assertEqual(m.group(0), "xyy")
71084d
+                self.assertEqual(m.group(1), "")
71084d
+                self.assertEqual(m.group(2), "y")
71084d
+
71084d
+
71084d
 
71084d
 def run_re_tests():
71084d
     from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR
71084d
diff --git a/Lib/doctest.py b/Lib/doctest.py
71084d
index 90bcca1..0ee40a2 100644
71084d
--- a/Lib/doctest.py
71084d
+++ b/Lib/doctest.py
71084d
@@ -564,7 +564,7 @@ class DocTestParser:
71084d
         # Want consists of any non-blank lines that do not start with PS1.
71084d
         (?P<want> (?:(?![ ]*$)    # Not a blank line
71084d
                      (?![ ]*>>>)  # Not a line starting with PS1
71084d
-                     .*$\n?       # But any other line
71084d
+                     .+$\n?       # But any other line
71084d
                   )*)
71084d
         ''', re.MULTILINE | re.VERBOSE)
71084d
 
71084d