This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ezio.melotti
Recipients ezio.melotti, terry.reedy
Date 2011-09-29.01:04:45
SpamBayes Score 5.551115e-17
Marked as misclassified No
Message-id <1317258287.26.0.710714873316.issue13052@psf.upfronthosting.co.za>
In-reply-to
Content
The problem is in Lib/idlelib/ReplaceDialog.py:141:
m = prog.match(chars, col)
if not prog:
    return False
new = m.expand(self.replvar.get())

where
prog = re.compile('foo')  # i.e. text in the find box
chars = '>>> "foo"\n'  # i.e. the text in the IDLE window
col = 5
self.replvar.get() = 'bar\'  # i.e. the var with the trailing \

m.expand() searches for groups to expand, like \1 and \2 to refer to the first and second matching group, and fails with:

Traceback (most recent call last):
  File "/home/wolf/dev/py/py3k/Lib/sre_parse.py", line 194, in __next
    c = self.string[self.index + 1]
IndexError: string index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/wolf/dev/py/py3k/Lib/re.py", line 278, in _expand
    template = sre_parse.parse_template(template, pattern)
  File "/home/wolf/dev/py/py3k/Lib/sre_parse.py", line 729, in parse_template
    this = sget()
  File "/home/wolf/dev/py/py3k/Lib/sre_parse.py", line 210, in get
    self.__next()
  File "/home/wolf/dev/py/py3k/Lib/sre_parse.py", line 196, in __next
    raise error("bogus escape (end of line)")
sre_constants.error: bogus escape (end of line)

Using things like foo\5bar also results in a crash because the group \5 is not found.

I'm not sure what the expected behavior should be.  If numeric/named backreferences are not supposed to be supported, I guess a re.escape() might solve the problem.  If they are supported the last line should be wrapped in a try/except that looks for sre_constants.error errors and possibly IndexErrors too (this might actually be fixed in sre_parse.py).

BTW, I think that "if not prog" in the snippet I pasted should be "if not m".  Pattern objects are always True (I assume prog is always a pattern object).

Do you want to work on a patch?
History
Date User Action Args
2011-09-29 01:04:47ezio.melottisetrecipients: + ezio.melotti, terry.reedy
2011-09-29 01:04:47ezio.melottisetmessageid: <1317258287.26.0.710714873316.issue13052@psf.upfronthosting.co.za>
2011-09-29 01:04:46ezio.melottilinkissue13052 messages
2011-09-29 01:04:45ezio.melotticreate