|
From: <no...@so...> - 2000-12-11 18:49:26
|
Bug #122815, was updated on 2000-Nov-18 11:13
Here is a current snapshot of the bug.
Project: Jython
Category: Library
Status: Closed
Resolution: Fixed
Bug Group: None
Priority: 1
Submitted by: bckfnn
Assigned to : nobody
Summary: Bug in MatchObject.group(PyString)
Details: There appears to be a bug either in MatchObject.java or in the regular
expression package (I've only tested using a distribution WITH
OROMatcher so far). For more complex regular expressions, it appears
that referencing a group in a match object by its name can cause an
IndexError. Following is a code snippet that demonstrates the
problem. I haven't been able to determine why exactly Case 3 works
whereas Case 1 fails inappropriately. Case 2 seems to fail
appropriately.
I have tested under all combinations of jdk 1.1/jdk 1.2 and jpython
1.1beta2/1.1beta3. The code snippet seems to behave as expected in
CPython.
-------------------------begin-----------------------------------
import re
# Regular expressions used for parsing
_S = '[ \t\r\n]+' # white space
_opS = '[ \t\r\n]*' # optional white space
_Name = '[a-zA-Z_:][-a-zA-Z0-9._:]*' # valid XML name
_QStr = "(?:'[^']*'|\"[^\"]*\")" # quoted XML string
attrfind = re.compile(
_S + '(?P<name>' + _Name + ')'
'(' + _opS + '=' + _opS +
'(?P<value>'+_QStr+'|[-a-zA-Z0-9.:+*%?!()_#=~]+))?')
starttagend = re.compile(_opS + '(?P<slash>/?)>')
## Case 1
starttagmatch = re.compile('<(?P<tagname>'+_Name+')'
'(?P<attrs>(?:'+attrfind.pattern+')*)'+
starttagend.pattern)
m = starttagmatch.match('<foo>')
try:
print '|%s|' % m.group('slash')
except IndexError, e:
print e
## Case 2
starttagmatch = re.compile('<(?P<tagname>'+_Name+')'
'(?P<attrs>(?:'+attrfind.pattern+')*)')
m = starttagmatch.match('<foo>')
try:
print '|%s|' % m.group('slash')
except IndexError, e:
print e
## Case 3
r = re.compile('<(?P<tagname>' + _Name + ')'
+ _opS + '(?P<slash>/?)>')
m = r.match('<foo>')
print '|%s|' % m.group('slash')
---------------------------end-----------------------------------
JPython output:
---------------
group 7 is undefined
group 'slash' is undefined
||
CPython output:
---------------
||
group 'slash' is undefined
||
Follow-Ups:
Date: 2000-Dec-11 10:49
By: bckfnn
Comment:
Closed when we switched to sre where the bug is solved.
-------------------------------------------------------
Date: 2000-Nov-19 08:25
By: bckfnn
Comment:
This works when using the "sre" moduled instead of "re".
-------------------------------------------------------
For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=122815&group_id=12867
|