mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-140797: Forbid capturing groups in re.Scanner lexicon patterns (GH-140944)
This commit is contained in:
parent
a84181c31b
commit
fa9c3eefd4
3 changed files with 24 additions and 1 deletions
|
|
@ -397,9 +397,12 @@ def __init__(self, lexicon, flags=0):
|
|||
s = _parser.State()
|
||||
s.flags = flags
|
||||
for phrase, action in lexicon:
|
||||
sub_pattern = _parser.parse(phrase, flags)
|
||||
if sub_pattern.state.groups != 1:
|
||||
raise ValueError("Cannot use capturing groups in re.Scanner")
|
||||
gid = s.opengroup()
|
||||
p.append(_parser.SubPattern(s, [
|
||||
(SUBPATTERN, (gid, 0, 0, _parser.parse(phrase, flags))),
|
||||
(SUBPATTERN, (gid, 0, 0, sub_pattern)),
|
||||
]))
|
||||
s.closegroup(gid, p[-1])
|
||||
p = _parser.SubPattern(s, [(BRANCH, (None, p))])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue