Skip to content
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

Closed
warsaw opened this issue Apr 18, 2002 · 3 comments
Closed

Wrong exception from re.compile() #36465

warsaw opened this issue Apr 18, 2002 · 3 comments

Comments

@warsaw
Copy link
Member

warsaw commented Apr 18, 2002

BPO 545855
Nosy @warsaw, @brettcannon

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:

assignee = None
closed_at = <Date 2003-05-17.01:53:02.000>
created_at = <Date 2002-04-18.22:22:48.000>
labels = ['expert-regex']
title = 'Wrong exception from re.compile()'
updated_at = <Date 2003-05-17.01:53:02.000>
user = 'https://github.com/warsaw'

bugs.python.org fields:

activity = <Date 2003-05-17.01:53:02.000>
actor = 'brett.cannon'
assignee = 'effbot'
closed = True
closed_date = None
closer = None
components = ['Regular Expressions']
creation = <Date 2002-04-18.22:22:48.000>
creator = 'barry'
dependencies = []
files = []
hgrepos = []
issue_num = 545855
keywords = []
message_count = 3.0
messages = ['10413', '10414', '10415']
nosy_count = 4.0
nosy_names = ['effbot', 'barry', 'brett.cannon', 'mbrierst']
pr_nums = []
priority = 'normal'
resolution = 'out of date'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue545855'
versions = ['Python 2.2']

@warsaw
Copy link
Member Author

warsaw commented Apr 18, 2002

re.compile('foo[a-') raises a TypeError exception
instead of re.error.

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

@mbrierst
Copy link
Mannequin

mbrierst mannequin commented Feb 4, 2003

Logged In: YES
user_id=670441

Patch below fixes the problem. Didn't check for end of expression in one case.

Index: dist/src/Lib/sre_parse.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/sre_parse.py,v
retrieving revision 1.55
diff -c -r1.55 sre_parse.py
*** dist/src/Lib/sre_parse.py 2 Jun 2002 00:40:05 -0000 1.55
--- dist/src/Lib/sre_parse.py 4 Feb 2003 19:53:14 -0000


*** 420,429 ****
set.append((LITERAL, ord("-")))
break
else:
! if this[0] == "\\":
code2 = _class_escape(source, this)
! else:
code2 = LITERAL, ord(this)
if code1[0] != LITERAL or code2[0] != LITERAL:
raise error, "bad character range"
lo = code1[1]
--- 420,431 ----

                          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]

@brettcannon
Copy link
Member

Logged In: YES
user_id=357491

This is fixed in 2.2.2 and 2.3b1. Closing as out of date.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants