aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_re.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_re.py')
-rw-r--r--Lib/test/test_re.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index 301d4a51656..1eca22f4537 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -1861,6 +1861,29 @@ class ReTests(unittest.TestCase):
self.assertRaises(OverflowError, re.compile, r".{%d,}?" % 2**128)
self.assertRaises(OverflowError, re.compile, r".{%d,%d}" % (2**129, 2**128))
+ def test_look_behind_overflow(self):
+ string = "x" * 2_500_000
+ p1 = r"(?<=((.{%d}){%d}){%d})"
+ p2 = r"(?<!((.{%d}){%d}){%d})"
+ # Test that the templates are valid and look-behind with width 2**21
+ # (larger than sys.maxunicode) are supported.
+ self.assertEqual(re.search(p1 % (2**7, 2**7, 2**7), string).span(),
+ (2**21, 2**21))
+ self.assertEqual(re.search(p2 % (2**7, 2**7, 2**7), string).span(),
+ (0, 0))
+ # Test that 2**22 is accepted as a repetition number and look-behind
+ # width.
+ re.compile(p1 % (2**22, 1, 1))
+ re.compile(p1 % (1, 2**22, 1))
+ re.compile(p1 % (1, 1, 2**22))
+ re.compile(p2 % (2**22, 1, 1))
+ re.compile(p2 % (1, 2**22, 1))
+ re.compile(p2 % (1, 1, 2**22))
+ # But 2**66 is too large for look-behind width.
+ errmsg = "looks too much behind"
+ self.assertRaisesRegex(re.error, errmsg, re.compile, p1 % (2**22, 2**22, 2**22))
+ self.assertRaisesRegex(re.error, errmsg, re.compile, p2 % (2**22, 2**22, 2**22))
+
def test_backref_group_name_in_exception(self):
# Issue 17341: Poor error message when compiling invalid regex
self.checkPatternError('(?P=<foo>)',