summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_re.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-02-16 19:23:53 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-02-16 19:23:53 (GMT)
commitfa4681691591429466d18e21d7640e3703ab7f28 (patch)
tree91ef35df8dbbfcf6cab1a0ce75e4495dcdf2f826 /Lib/test/test_re.py
parent70ca0210e8958d2665541ddd38fce2965075674e (diff)
downloadcpython-fa4681691591429466d18e21d7640e3703ab7f28.zip
cpython-fa4681691591429466d18e21d7640e3703ab7f28.tar.gz
cpython-fa4681691591429466d18e21d7640e3703ab7f28.tar.bz2
Issue #9669: Protect re against infinite loops on zero-width matching in
non-greedy repeat. Patch by Matthew Barnett.
Diffstat (limited to 'Lib/test/test_re.py')
-rw-r--r--Lib/test/test_re.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index f7e76dc..0c95f4e 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -616,6 +616,15 @@ class ReTests(unittest.TestCase):
self.assertEqual(re.match('(x)*y', 50000*'x'+'y').group(1), 'x')
self.assertEqual(re.match('(x)*?y', 50000*'x'+'y').group(1), 'x')
+ def test_unlimited_zero_width_repeat(self):
+ # Issue #9669
+ self.assertIsNone(re.match(r'(?:a?)*y', 'z'))
+ self.assertIsNone(re.match(r'(?:a?)+y', 'z'))
+ self.assertIsNone(re.match(r'(?:a?){2,}y', 'z'))
+ self.assertIsNone(re.match(r'(?:a?)*?y', 'z'))
+ self.assertIsNone(re.match(r'(?:a?)+?y', 'z'))
+ self.assertIsNone(re.match(r'(?:a?){2,}?y', 'z'))
+
def test_scanner(self):
def s_ident(scanner, token): return token
def s_operator(scanner, token): return "op%s" % token