self.assertEqual(re.match("(?>(?:ab?c){1,3})", "aca").span(), (0, 2))
self.assertEqual(re.match("(?:ab?c){1,3}+", "aca").span(), (0, 2))
+ def test_bug_gh101955(self):
+ # Possessive quantifier with nested alternative with capture groups
+ self.assertEqual(re.match('((x)|y|z)*+', 'xyz').groups(), ('z', 'x'))
+ self.assertEqual(re.match('((x)|y|z){3}+', 'xyz').groups(), ('z', 'x'))
+ self.assertEqual(re.match('((x)|y|z){3,}+', 'xyz').groups(), ('z', 'x'))
+
@unittest.skipIf(multiprocessing is None, 'test requires multiprocessing')
def test_regression_gh94675(self):
pattern = re.compile(r'(?<=[({}])(((//[^\n]*)?[\n])([\000-\040])*)*'
--- /dev/null
+Fix SystemError when match regular expression pattern containing some
+combination of possessive quantifier, alternative and capture group.
pointer */
state->ptr = ptr;
+ /* Set state->repeat to non-NULL */
+ ctx->u.rep = repeat_pool_malloc(state);
+ if (!ctx->u.rep) {
+ RETURN_ERROR(SRE_ERROR_MEMORY);
+ }
+ ctx->u.rep->count = -1;
+ ctx->u.rep->pattern = NULL;
+ ctx->u.rep->prev = state->repeat;
+ ctx->u.rep->last_ptr = NULL;
+ state->repeat = ctx->u.rep;
+
/* Initialize Count to 0 */
ctx->count = 0;
}
else {
state->ptr = ptr;
+ /* Restore state->repeat */
+ state->repeat = ctx->u.rep->prev;
+ repeat_pool_free(state, ctx->u.rep);
RETURN_FAILURE;
}
}
}
}
+ /* Restore state->repeat */
+ state->repeat = ctx->u.rep->prev;
+ repeat_pool_free(state, ctx->u.rep);
+
/* Evaluate Tail */
/* Jump to end of pattern indicated by skip, and then skip
the SUCCESS op code that follows it. */