Commit 7c1455be authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #25554: Got rid of circular references in regular expression parsing.

parents 12b2538a b5d0a215
...@@ -70,14 +70,14 @@ class Pattern: ...@@ -70,14 +70,14 @@ class Pattern:
def __init__(self): def __init__(self):
self.flags = 0 self.flags = 0
self.groupdict = {} self.groupdict = {}
self.subpatterns = [None] # group 0 self.groupwidths = [None] # group 0
self.lookbehindgroups = None self.lookbehindgroups = None
@property @property
def groups(self): def groups(self):
return len(self.subpatterns) return len(self.groupwidths)
def opengroup(self, name=None): def opengroup(self, name=None):
gid = self.groups gid = self.groups
self.subpatterns.append(None) self.groupwidths.append(None)
if self.groups > MAXGROUPS: if self.groups > MAXGROUPS:
raise error("too many groups") raise error("too many groups")
if name is not None: if name is not None:
...@@ -88,9 +88,9 @@ class Pattern: ...@@ -88,9 +88,9 @@ class Pattern:
self.groupdict[name] = gid self.groupdict[name] = gid
return gid return gid
def closegroup(self, gid, p): def closegroup(self, gid, p):
self.subpatterns[gid] = p self.groupwidths[gid] = p.getwidth()
def checkgroup(self, gid): def checkgroup(self, gid):
return gid < self.groups and self.subpatterns[gid] is not None return gid < self.groups and self.groupwidths[gid] is not None
def checklookbehindgroup(self, gid, source): def checklookbehindgroup(self, gid, source):
if self.lookbehindgroups is not None: if self.lookbehindgroups is not None:
...@@ -195,7 +195,7 @@ class SubPattern: ...@@ -195,7 +195,7 @@ class SubPattern:
lo = lo + 1 lo = lo + 1
hi = hi + 1 hi = hi + 1
elif op is GROUPREF: elif op is GROUPREF:
i, j = self.pattern.subpatterns[av].getwidth() i, j = self.pattern.groupwidths[av]
lo = lo + i lo = lo + i
hi = hi + j hi = hi + j
elif op is GROUPREF_EXISTS: elif op is GROUPREF_EXISTS:
......
...@@ -72,6 +72,8 @@ Core and Builtins ...@@ -72,6 +72,8 @@ Core and Builtins
Library Library
------- -------
- Issue #25554: Got rid of circular references in regular expression parsing.
- Issue #18973: Command-line interface of the calendar module now uses argparse - Issue #18973: Command-line interface of the calendar module now uses argparse
instead of optparse. instead of optparse.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment