| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 24fb627 commit 89bf9dc
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -100,6 +100,13 @@ def _compile(code, pattern, flags): | |||
| 100 | 100 | emit(ANY_ALL) | |
| 101 | 101 | else: | |
| 102 | 102 | emit(ANY) | |
| 103 | + elif op is POSSESSIVE_REPEAT: | ||
| 104 | + # gh-106052: Possessive quantifiers do not work when the | ||
| 105 | + # subpattern contains backtracking, i.e. "(?:ab?c)*+". | ||
| 106 | + # Implement it as equivalent greedy qualifier in atomic group. | ||
| 107 | + p = [(MAX_REPEAT, av)] | ||
| 108 | + p = [(ATOMIC_GROUP, p)] | ||
| 109 | + _compile(code, p, flags) | ||
| 103 | 110 | elif op in REPEATING_CODES: | |
| 104 | 111 | if _simple(av[2]): | |
| 105 | 112 | emit(REPEATING_CODES[op][2]) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2398,6 +2398,16 @@ def test_bug_gh91616(self): | |||
| 2398 | 2398 | self.assertTrue(re.fullmatch(r'(?s:(?>.*?\.).*)\Z', "a.txt")) # reproducer | |
| 2399 | 2399 | self.assertTrue(re.fullmatch(r'(?s:(?=(?P<g0>.*?\.))(?P=g0).*)\Z', "a.txt")) | |
| 2400 | 2400 | ||
| 2401 | + def test_bug_gh106052(self): | ||
| 2402 | + self.assertEqual(re.match("(?>(?:ab?c)+)", "aca").span(), (0, 2)) | ||
| 2403 | + self.assertEqual(re.match("(?:ab?c)++", "aca").span(), (0, 2)) | ||
| 2404 | + self.assertEqual(re.match("(?>(?:ab?c)*)", "aca").span(), (0, 2)) | ||
| 2405 | + self.assertEqual(re.match("(?:ab?c)*+", "aca").span(), (0, 2)) | ||
| 2406 | + self.assertEqual(re.match("(?>(?:ab?c)?)", "a").span(), (0, 0)) | ||
| 2407 | + self.assertEqual(re.match("(?:ab?c)?+", "a").span(), (0, 0)) | ||
| 2408 | + self.assertEqual(re.match("(?>(?:ab?c){1,3})", "aca").span(), (0, 2)) | ||
| 2409 | + self.assertEqual(re.match("(?:ab?c){1,3}+", "aca").span(), (0, 2)) | ||
| 2410 | + | ||
| 2401 | 2411 | @unittest.skipIf(multiprocessing is None, 'test requires multiprocessing') | |
| 2402 | 2412 | def test_regression_gh94675(self): | |
| 2403 | 2413 | pattern = re.compile(r'(?<=[({}])(((//[^\n]*)?[\n])([\000-\040])*)*' | |
@@ -2491,6 +2501,7 @@ def test_atomic_group(self): | |||
| 2491 | 2501 | 17: SUCCESS | |
| 2492 | 2502 | ''') | |
| 2493 | 2503 | ||
| 2504 | + @unittest.expectedFailure # gh-106052 | ||
| 2494 | 2505 | def test_possesive_repeat_one(self): | |
| 2495 | 2506 | self.assertEqual(get_debug_out(r'a?+'), '''\ | |
| 2496 | 2507 | POSSESSIVE_REPEAT 0 1 | |
@@ -2503,6 +2514,7 @@ def test_possesive_repeat_one(self): | |||
| 2503 | 2514 | 12: SUCCESS | |
| 2504 | 2515 | ''') | |
| 2505 | 2516 | ||
| 2517 | + @unittest.expectedFailure # gh-106052 | ||
| 2506 | 2518 | def test_possesive_repeat(self): | |
| 2507 | 2519 | self.assertEqual(get_debug_out(r'(?:ab)?+'), '''\ | |
| 2508 | 2520 | POSSESSIVE_REPEAT 0 1 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + :mod:`re` module: fix the matching of possessive quantifiers in the case of | ||
| 2 | + a subpattern containing backtracking. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments