mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Issue #9669: Protect re against infinite loops on zero-width matching in
non-greedy repeat. Patch by Matthew Barnett.
This commit is contained in:
commit
b0c75a7dec
3 changed files with 19 additions and 2 deletions
|
@ -681,6 +681,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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue