[Patches] [Patch #101612] Prevent recursion limit when using ".*?xxx"

noreply@sourceforge.net noreply@sourceforge.net
Fri, 22 Sep 2000 21:23:43 -0700


Patch #101612 has been updated. 

Project: 
Category: Modules
Status: Open
Summary: Prevent recursion limit when using ".*?xxx"

Follow-Ups:

Date: 2000-Sep-22 21:12
By: dgallion

Comment:
This pattern fails with sre:
>>> re.match("(?s){.*?}","{"+' '*17000+"}")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "E:\pythonWinCVS\python\dist\src\lib\sre.py", line 44, in match
    return _compile(pattern, flags).match(string)
RuntimeError: maximum recursion limit exceeded

The same pattern with even a much larger search buffer works fine on 1.52

This patch optimizes the case ".*?"  and avoids the recursion limit.

After the patch:
>>> import re
>>> re.findall('ab.*?bc', 'abababbc')
['abababbc']
>>> re.findall('ab??bc', 'abababbc')
['abbc']
>>> re.sub("(?s){.*?}","","{"+' '*19047+"}")
''
>>> re.match("(?s){.*?}","{"+' '*16048+"}")
<SRE_Match object at 007E4490>
>>> import test.test_re
Running tests on re.search and re.match
Running tests on re.sub
Running tests on symbolic references
Running tests on re.subn
Running tests on re.split
Running tests on re.findall
Running tests on re.match
Running tests on re.escape
Pickling a RegexObject instance
Test engine limitations
maximum recursion limit exceeded
Running re_tests test suite
>>>



-------------------------------------------------------

Date: 2000-Sep-22 21:23
By: tim_one

Comment:
Assigned to Fredrik.

dgallion, please resubmit a context diff.  Straight diffs aren't accepted (they're too brittle).

-------------------------------------------------------

-------------------------------------------------------
For more info, visit:

http://sourceforge.net/patch/?func=detailpatch&patch_id=101612&group_id=5470