New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong exception from re.compile() #36465
Comments
re.compile('foo[a-') raises a TypeError exception Python 2.2.1 (#1, Apr 4 2002, 17:22:15)
[GCC 2.96 20000731 (Mandrake Linux 8.2 2.96-0.76mdk)]
on linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>> import re
>>> re.compile('foo[a-')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/local/lib/python2.2/sre.py", line 178, in
compile
return _compile(pattern, flags)
File "/usr/local/lib/python2.2/sre.py", line 226, in
_compile
p = sre_compile.compile(pattern, flags)
File "/usr/local/lib/python2.2/sre_compile.py", line
430, in compile
p = sre_parse.parse(p, flags)
File "/usr/local/lib/python2.2/sre_parse.py", line
623, in parse
p = _parse_sub(source, pattern, 0)
File "/usr/local/lib/python2.2/sre_parse.py", line
318, in _parse_sub
items.append(_parse(source, state))
File "/usr/local/lib/python2.2/sre_parse.py", line
424, in _parse
if this[0] == "\\":
TypeError: unsubscriptable object |
Logged In: YES Patch below fixes the problem. Didn't check for end of expression in one case. Index: dist/src/Lib/sre_parse.py *** 420,429 **** set.append((LITERAL, ord("-")))
break
else:
! if this and this[0] == "\\":
code2 = _class_escape(source, this)
! elif this:
code2 = LITERAL, ord(this)
+ else:
+ raise error, "unexpected end of regular expression"
if code1[0] != LITERAL or code2[0] != LITERAL:
raise error, "bad character range"
lo = code1[1] |
Logged In: YES This is fixed in 2.2.2 and 2.3b1. Closing as out of date. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: