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
re.finditer hangs on final empty match #39362
Comments
The iterator returned by re.finditer appears to not Is this a bug in _sre? If so, I'll be happy to file Code to illustrate the failure: from re import finditer
last = None
for m in finditer( ".*", "asdf" ):
if last == m.span():
print "duplicate match:", last
break
print m.group(), m.span()
last = m.span()
asdf (0, 4) findall works: print re.findall( ".*", "asdf" ) Workaround is to explicitly check for a duplicate span, Seo Sanghyeon sent the following fix to python-dev list: Attached one line patch fixes re.finditer bug reported by But that bug didn't appear after my patch, so I wonder To test: python/cpython#36890
import re
list(re.finditer('\s', 'a b'))
# expected: one item list
# bug: hang
#Kevin J. Butler
import re
list(re.finditer('.*', 'asdf'))
# expected: two item list (?)
# bug: hang Seo Sanghyeon *** 3062,3069 **** ! if ((status == 0 || state->ptr == state->start) && match = pattern_new_match((PatternObject*)
self->pattern,
state, status);
! if (status == 0 || state->ptr == state->start)
state->start = (void*) ((char*) state->ptr +
state->charsize);
else
state->start = state->ptr; |
Logged In: YES The above patch does resolve the problem. The code was introduced in rev 2.85 Thanks, and kudos to Seo... |
Logged In: YES Still there in 2.4a3, as the following revised example shows: import re
m = re.finditer(".*", "asdf") print m.next().span() Gustavo, can you look at this patch too? |
Logged In: YES Patch applied and test cases added to check this bug and also for Kevin and Seo, thanks for the bug report and the fix. Fredrik, thanks for pointing me to the issue. Applied as: Lib/test/test_re.py: 1.52 Patch attached for reference. |
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: