[Python-checkins] CVS: python/dist/src/Lib sre.py,1.9,1.10 sre_compile.py,1.7,1.8 sre_constants.py,1.7,1.8 sre_parse.py,1.7,1.8
Fredrik Lundh
python-dev@python.org
Thu, 29 Jun 2000 05:38:48 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory slayer.i.sourceforge.net:/tmp/cvs-serv899/Lib
Modified Files:
sre.py sre_compile.py sre_constants.py sre_parse.py
Log Message:
- make sure group names are valid identifiers
(closes the "SRE: symbolic reference" bug)
Index: sre.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sre.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
Index: sre_compile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sre_compile.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
Index: sre_constants.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sre_constants.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
Index: sre_parse.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sre_parse.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** sre_parse.py 2000/06/29 11:34:27 1.7
--- sre_parse.py 2000/06/29 12:38:45 1.8
***************
*** 169,172 ****
--- 169,190 ----
return this
+ def isident(char):
+ return "a" <= char <= "z" or "A" <= char <= "Z" or char == "_"
+
+ def isdigit(char):
+ return "0" <= char <= "9"
+
+ def isname(name):
+ # check that group name is a valid string
+ # FIXME: <fl> this code is really lame. should use a regular
+ # expression instead, but I seem to have certain bootstrapping
+ # problems here ;-)
+ if not isident(name[0]):
+ return 0
+ for char in name:
+ if not isident(char) and not isdigit(char):
+ return 0
+ return 1
+
def _group(escape, state):
# check if the escape string represents a valid group
***************
*** 419,425 ****
if char == ">":
break
- # FIXME: check for valid character
name = name + char
group = 1
elif source.match("="):
# named backreference
--- 437,444 ----
if char == ">":
break
name = name + char
group = 1
+ if not isname(name):
+ raise error, "illegal character in group name"
elif source.match("="):
# named backreference
***************
*** 523,540 ****
char = s.get()
if char is None:
! raise error, "unterminated index"
if char == ">":
break
- # FIXME: check for valid character
name = name + char
if not name:
! raise error, "bad index"
try:
index = int(name)
except ValueError:
try:
index = pattern.groupindex[name]
except KeyError:
! raise IndexError, "unknown index"
a((MARK, index))
elif len(this) > 1 and this[1] in DIGITS:
--- 542,560 ----
char = s.get()
if char is None:
! raise error, "unterminated group name"
if char == ">":
break
name = name + char
if not name:
! raise error, "bad group name"
try:
index = int(name)
except ValueError:
+ if not isname(name):
+ raise error, "illegal character in group name"
try:
index = pattern.groupindex[name]
except KeyError:
! raise IndexError, "unknown group name"
a((MARK, index))
elif len(this) > 1 and this[1] in DIGITS: