Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc2c18ac

Browse files
[3.13]gh-101955: Fix SystemError in possesive quantifier with alternative and group (GH-111362) (GH-126962)
(cherry picked from commitf9c5573)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent885386b commitc2c18ac

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

‎Lib/test/test_re.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,6 +2641,12 @@ def test_bug_gh100061(self):
26412641
self.assertEqual(re.match("(?>(?:ab?c){1,3})","aca").span(), (0,2))
26422642
self.assertEqual(re.match("(?:ab?c){1,3}+","aca").span(), (0,2))
26432643

2644+
deftest_bug_gh101955(self):
2645+
# Possessive quantifier with nested alternative with capture groups
2646+
self.assertEqual(re.match('((x)|y|z)*+','xyz').groups(), ('z','x'))
2647+
self.assertEqual(re.match('((x)|y|z){3}+','xyz').groups(), ('z','x'))
2648+
self.assertEqual(re.match('((x)|y|z){3,}+','xyz').groups(), ('z','x'))
2649+
26442650
@unittest.skipIf(multiprocessingisNone,'test requires multiprocessing')
26452651
deftest_regression_gh94675(self):
26462652
pattern=re.compile(r'(?<=[({}])(((//[^\n]*)?[\n])([\000-\040])*)*'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix SystemError when match regular expression pattern containing some
2+
combination of possessive quantifier, alternative and capture group.

‎Modules/_sre/sre_lib.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,17 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
13061306
pointer */
13071307
state->ptr=ptr;
13081308

1309+
/* Set state->repeat to non-NULL */
1310+
ctx->u.rep=repeat_pool_malloc(state);
1311+
if (!ctx->u.rep) {
1312+
RETURN_ERROR(SRE_ERROR_MEMORY);
1313+
}
1314+
ctx->u.rep->count=-1;
1315+
ctx->u.rep->pattern=NULL;
1316+
ctx->u.rep->prev=state->repeat;
1317+
ctx->u.rep->last_ptr=NULL;
1318+
state->repeat=ctx->u.rep;
1319+
13091320
/* Initialize Count to 0 */
13101321
ctx->count=0;
13111322

@@ -1320,6 +1331,9 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
13201331
}
13211332
else {
13221333
state->ptr=ptr;
1334+
/* Restore state->repeat */
1335+
state->repeat=ctx->u.rep->prev;
1336+
repeat_pool_free(state,ctx->u.rep);
13231337
RETURN_FAILURE;
13241338
}
13251339
}
@@ -1392,6 +1406,10 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
13921406
}
13931407
}
13941408

1409+
/* Restore state->repeat */
1410+
state->repeat=ctx->u.rep->prev;
1411+
repeat_pool_free(state,ctx->u.rep);
1412+
13951413
/* Evaluate Tail */
13961414
/* Jump to end of pattern indicated by skip, and then skip
13971415
the SUCCESS op code that follows it. */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp