[3.11] gh-106052: Fix bug in the matching of possessive quantifiers (GH-106515) (GH-107795)

It did not work in the case of a subpattern containing backtracking.

Temporary implement possessive quantifiers as equivalent greedy qualifiers
in atomic groups.
(cherry picked from commit 7b6e34e5ba)
This commit is contained in:
Serhiy Storchaka 2023-08-09 09:15:27 +03:00 committed by GitHub
parent edaa0db93e
commit 5b76eaf02e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 0 deletions

View file

@ -2396,6 +2396,16 @@ class ReTests(unittest.TestCase):
self.assertTrue(template_re1.match('ahoy'))
self.assertFalse(template_re1.match('nope'))
def test_bug_gh106052(self):
self.assertEqual(re.match("(?>(?:ab?c)+)", "aca").span(), (0, 2))
self.assertEqual(re.match("(?:ab?c)++", "aca").span(), (0, 2))
self.assertEqual(re.match("(?>(?:ab?c)*)", "aca").span(), (0, 2))
self.assertEqual(re.match("(?:ab?c)*+", "aca").span(), (0, 2))
self.assertEqual(re.match("(?>(?:ab?c)?)", "a").span(), (0, 0))
self.assertEqual(re.match("(?:ab?c)?+", "a").span(), (0, 0))
self.assertEqual(re.match("(?>(?:ab?c){1,3})", "aca").span(), (0, 2))
self.assertEqual(re.match("(?:ab?c){1,3}+", "aca").span(), (0, 2))
@unittest.skipIf(multiprocessing is None, 'test requires multiprocessing')
def test_regression_gh94675(self):
pattern = re.compile(r'(?<=[({}])(((//[^\n]*)?[\n])([\000-\040])*)*'
@ -2492,6 +2502,7 @@ ATOMIC_GROUP
17: SUCCESS
''')
@unittest.expectedFailure # gh-106052
def test_possesive_repeat_one(self):
self.assertEqual(get_debug_out(r'a?+'), '''\
POSSESSIVE_REPEAT 0 1
@ -2504,6 +2515,7 @@ POSSESSIVE_REPEAT 0 1
12: SUCCESS
''')
@unittest.expectedFailure # gh-106052
def test_possesive_repeat(self):
self.assertEqual(get_debug_out(r'(?:ab)?+'), '''\
POSSESSIVE_REPEAT 0 1