diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2023-08-09 05:47:57 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-09 05:47:57 (GMT) |
commit | 7b6e34e5baeb4162815ffa4d943b09a58e3f6580 (patch) | |
tree | 8fbfdfcd748b84975429eea8f71fa71308c747fa /Lib/re/_compiler.py | |
parent | 73507382ac184a72b59ebb0c2f85e8b1d2dfa58e (diff) | |
download | cpython-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/re/_compiler.py')
-rw-r--r-- | Lib/re/_compiler.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/re/_compiler.py b/Lib/re/_compiler.py index d0a4c55..f5fd160 100644 --- a/Lib/re/_compiler.py +++ b/Lib/re/_compiler.py @@ -100,6 +100,13 @@ def _compile(code, pattern, flags): emit(ANY_ALL) else: emit(ANY) + elif op is POSSESSIVE_REPEAT: + # gh-106052: Possessive quantifiers do not work when the + # subpattern contains backtracking, i.e. "(?:ab?c)*+". + # Implement it as equivalent greedy qualifier in atomic group. + p = [(MAX_REPEAT, av)] + p = [(ATOMIC_GROUP, p)] + _compile(code, p, flags) elif op in REPEATING_CODES: if _simple(av[2]): emit(REPEATING_CODES[op][2]) |