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

[3.13] gh-101955: Fix SystemError in possesive quantifier with alternative and group (GH-111362)#126962

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-101955: Fix SystemError in possesive quantifier with alternative a…
…nd group (GH-111362)(cherry picked from commitf9c5573)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>Co-authored-by: <wjssz@users.noreply.github.com>
  • Loading branch information
@serhiy-storchaka@miss-islington
serhiy-storchaka authored andmiss-islington committedNov 18, 2024
commit4002a3440c9e21cd0744088c904d277aba3e1be2
6 changes: 6 additions & 0 deletionsLib/test/test_re.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2641,6 +2641,12 @@ def test_bug_gh100061(self):
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])*)*'
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
Fix SystemError when match regular expression pattern containing some
combination of possessive quantifier, alternative and capture group.
18 changes: 18 additions & 0 deletionsModules/_sre/sre_lib.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1306,6 +1306,17 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
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;

Expand All@@ -1320,6 +1331,9 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
}
else {
state->ptr = ptr;
/* Restore state->repeat */
state->repeat = ctx->u.rep->prev;
repeat_pool_free(state, ctx->u.rep);
RETURN_FAILURE;
}
}
Expand DownExpand Up@@ -1392,6 +1406,10 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
}
}

/* 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. */
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp