summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_re.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-08-09 05:47:57 (GMT)
committerGitHub <noreply@github.com>2023-08-09 05:47:57 (GMT)
commit7b6e34e5baeb4162815ffa4d943b09a58e3f6580 (patch)
tree8fbfdfcd748b84975429eea8f71fa71308c747fa /Lib/test/test_re.py
parent73507382ac184a72b59ebb0c2f85e8b1d2dfa58e (diff)
downloadcpython-7b6e34e5baeb4162815ffa4d943b09a58e3f6580.zip
cpython-7b6e34e5baeb4162815ffa4d943b09a58e3f6580.tar.gz
cpython-7b6e34e5baeb4162815ffa4d943b09a58e3f6580.tar.bz2
gh-106052: Fix bug in the matching of possessive quantifiers (gh-106515)
It did not work in the case of a subpattern containing backtracking. Temporary implement possessive quantifiers as equivalent greedy qualifiers in atomic groups.
Diffstat (limited to 'Lib/test/test_re.py')
-rw-r--r--Lib/test/test_re.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index a565cbe..bf3698a 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -2342,6 +2342,16 @@ class ReTests(unittest.TestCase):
self.assertTrue(re.fullmatch(r'(?s:(?>.*?\.).*)\Z', "a.txt")) # reproducer
self.assertTrue(re.fullmatch(r'(?s:(?=(?P<g0>.*?\.))(?P=g0).*)\Z', "a.txt"))
+ 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])*)*'
@@ -2441,6 +2451,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
@@ -2453,6 +2464,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