Fix re.fullmatch POSSESSIVE_REPEAT by wvmscs · Pull Request #7187 · RustPython/RustPython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 0 additions & 3 deletions Lib/test/test_re.py
13 changes: 10 additions & 3 deletions crates/sre_engine/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,10 @@ fn _match<S: StrDrive>(req: &Request<'_, S>, state: &mut State, mut ctx: MatchCo
Jump::PossessiveRepeat1 => {
let min_count = ctx.peek_code(req, 2) as isize;
if ctx.count < min_count {
break 'context ctx.next_offset(4, Jump::PossessiveRepeat2);
// modified next.toplevel from inherited to false
let mut next = ctx.next_offset(4, Jump::PossessiveRepeat2);
next.toplevel = false;
break 'context next;
}
// zero match protection
ctx.cursor.position = usize::MAX;
Expand All @@ -494,7 +497,9 @@ fn _match<S: StrDrive>(req: &Request<'_, S>, state: &mut State, mut ctx: MatchCo
{
state.marks.push();
ctx.cursor = state.cursor;
break 'context ctx.next_offset(4, Jump::PossessiveRepeat4);
let mut next = ctx.next_offset(4, Jump::PossessiveRepeat4);
next.toplevel = false; // modified next.toplevel from inherited to false
break 'context next;
}
ctx.cursor = state.cursor;
ctx.skip_code_from(req, 1);
Expand Down Expand Up @@ -832,7 +837,9 @@ fn _match<S: StrDrive>(req: &Request<'_, S>, state: &mut State, mut ctx: MatchCo
/* <ATOMIC_GROUP> <skip> pattern <SUCCESS> tail */
SreOpcode::ATOMIC_GROUP => {
state.cursor = ctx.cursor;
break 'context ctx.next_offset(2, Jump::AtomicGroup1);
let mut next_ctx = ctx.next_offset(2, Jump::AtomicGroup1);
next_ctx.toplevel = false; // modified next.toplevel from inherited to false
break 'context next_ctx;
}
/* <POSSESSIVE_REPEAT> <skip> <1=min> <2=max> pattern
<SUCCESS> tail */
Expand Down
12 changes: 12 additions & 0 deletions crates/sre_engine/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ fn test_possessive_quantifier() {
assert!(state.py_match(&req));
}

#[test]
fn test_possessive_repeat_fullmatch() {
// pattern p = re.compile("([0-9]++(?:\.[0-9]+)*+)", re.I )
// [INFO, 4, 0, 1, 4294967295, MARK, 0, POSSESSIVE_REPEAT_ONE, 10, 1, MAXREPEAT, IN, 5, RANGE, 48, 57, FAILURE, SUCCESS, POSSESSIVE_REPEAT, 16, 0, MAXREPEAT, LITERAL, 46, REPEAT_ONE, 10, 1, MAXREPEAT, IN, 5, RANGE, 48, 57, FAILURE, SUCCESS, SUCCESS, MARK, 1, SUCCESS]
// START GENERATED by generate_tests.py
#[rustfmt::skip] let p = Pattern { pattern: "([0-9]++(?:\\.[0-9]+)*+)", code: &[14, 4, 0, 1, 4294967295, 17, 0, 29, 10, 1, 4294967295, 13, 5, 22, 48, 57, 0, 1, 28, 16, 0, 4294967295, 16, 46, 24, 10, 1, 4294967295, 13, 5, 22, 48, 57, 0, 1, 1, 17, 1, 1] };
// END GENERATED
let (mut req, mut state) = p.state("1.25.38");
req.match_all = true;
assert!(state.py_match(&req), "should match");
}

#[test]
fn test_possessive_atomic_group() {
// pattern p = re.compile('(?>x)++x')
Expand Down
4 changes: 4 additions & 0 deletions extra_tests/snippets/stdlib_re.py
Loading