gh-106566: Optimize (?!) in regular expressions (GH-106567)

This commit is contained in:
Serhiy Storchaka 2023-08-07 18:09:56 +03:00 committed by GitHub
parent 50e3cc9748
commit ed64204716
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 1 deletions

View File

@ -773,8 +773,10 @@ def _parse(source, state, verbose, nested, first=False):
source.tell() - start)
if char == "=":
subpatternappend((ASSERT, (dir, p)))
else:
elif p:
subpatternappend((ASSERT_NOT, (dir, p)))
else:
subpatternappend((FAILURE, ()))
continue
elif char == "(":

View File

@ -2362,6 +2362,9 @@ class ReTests(unittest.TestCase):
p.terminate()
p.join()
def test_fail(self):
self.assertEqual(re.search(r'12(?!)|3', '123')[0], '3')
def get_debug_out(pat):
with captured_stdout() as out:

View File

@ -0,0 +1 @@
Optimize ``(?!)`` (pattern which alwais fails) in regular expressions.