Fixing bug #817234, which made SRE get into an infinite loop on
empty final matches with finditer(). New test cases included for this bug and for #581080.
This commit is contained in:
parent
a01a2ee933
commit
0506c64086
|
@ -567,6 +567,22 @@ class ReTests(unittest.TestCase):
|
|||
self.assertEqual(re.compile(pattern).split("a.b.c"),
|
||||
['a','b','c'])
|
||||
|
||||
def test_bug_581080(self):
|
||||
iter = re.finditer(r"\s", "a b")
|
||||
self.assertEqual(iter.next().span(), (1,2))
|
||||
self.assertRaises(StopIteration, iter.next)
|
||||
|
||||
scanner = re.compile(r"\s").scanner("a b")
|
||||
self.assertEqual(scanner.search().span(), (1, 2))
|
||||
self.assertEqual(scanner.search(), None)
|
||||
|
||||
def test_bug_817234(self):
|
||||
iter = re.finditer(r".*", "asdf")
|
||||
self.assertEqual(iter.next().span(), (0, 4))
|
||||
self.assertEqual(iter.next().span(), (4, 4))
|
||||
self.assertRaises(StopIteration, iter.next)
|
||||
|
||||
|
||||
def run_re_tests():
|
||||
from test.re_tests import benchmarks, tests, SUCCEED, FAIL, SYNTAX_ERROR
|
||||
if verbose:
|
||||
|
|
|
@ -539,7 +539,7 @@ SRE_COUNT(SRE_STATE* state, SRE_CODE* pattern, int maxcount)
|
|||
break;
|
||||
|
||||
case SRE_OP_ANY_ALL:
|
||||
/* repeated dot wildcare. skip to the end of the target
|
||||
/* repeated dot wildcard. skip to the end of the target
|
||||
string, and backtrack from there */
|
||||
TRACE(("|%p|%p|COUNT ANY_ALL\n", pattern, ptr));
|
||||
ptr = end;
|
||||
|
@ -3244,8 +3244,7 @@ scanner_match(ScannerObject* self, PyObject* args)
|
|||
match = pattern_new_match((PatternObject*) self->pattern,
|
||||
state, status);
|
||||
|
||||
if ((status == 0 || state->ptr == state->start) &&
|
||||
state->ptr < state->end)
|
||||
if (status == 0 || state->ptr == state->start)
|
||||
state->start = (void*) ((char*) state->ptr + state->charsize);
|
||||
else
|
||||
state->start = state->ptr;
|
||||
|
@ -3276,8 +3275,7 @@ scanner_search(ScannerObject* self, PyObject* args)
|
|||
match = pattern_new_match((PatternObject*) self->pattern,
|
||||
state, status);
|
||||
|
||||
if ((status == 0 || state->ptr == state->start) &&
|
||||
state->ptr < state->end)
|
||||
if (status == 0 || state->ptr == state->start)
|
||||
state->start = (void*) ((char*) state->ptr + state->charsize);
|
||||
else
|
||||
state->start = state->ptr;
|
||||
|
|
Loading…
Reference in New Issue