Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
Original file line number Diff line number Diff line change
Expand Up @@ -2537,7 +2537,6 @@ def test_possessive_quantifiers(self):
self.assertIsNone(re.match("^x{}+$", "xxx"))
self.assertTrue(re.match("^x{}+$", "x{}"))

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_fullmatch_possessive_quantifiers(self):
self.assertTrue(re.fullmatch(r'a++', 'a'))
self.assertTrue(re.fullmatch(r'a*+', 'a'))
Expand Down Expand Up @@ -2590,7 +2589,6 @@ def test_atomic_grouping(self):
self.assertIsNone(re.match(r'(?>x)++x', 'xxx'))
self.assertIsNone(re.match(r'(?>x++)x', 'xxx'))

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_fullmatch_atomic_grouping(self):
self.assertTrue(re.fullmatch(r'(?>a+)', 'a'))
self.assertTrue(re.fullmatch(r'(?>a*)', 'a'))
Expand Down Expand Up @@ -2629,7 +2627,6 @@ def test_findall_atomic_grouping(self):
self.assertEqual(re.findall(r'(?>(?:ab)?)', 'ababc'), ['ab', 'ab', '', ''])
self.assertEqual(re.findall(r'(?>(?:ab){1,3})', 'ababc'), ['abab'])

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_bug_gh91616(self):
self.assertTrue(re.fullmatch(r'(?s:(?>.*?\.).*)\z', "a.txt")) # reproducer
self.assertTrue(re.fullmatch(r'(?s:(?=(?P<g0>.*?\.))(?P=g0).*)\z', "a.txt"))
Expand Down
1 change: 1 addition & 0 deletions crates/sre_engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ license.workspace = true
name = "benches"
harness = false


Comment thread
youknowone marked this conversation as resolved.
Outdated
[dependencies]
rustpython-wtf8 = { workspace = true }
num_enum = { workspace = true }
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@

assert re.compile("(?:\w+(?:\s|/(?!>))*)*").match("a /bb />ccc").group() == "a /bb "
assert re.compile("(?:(1)?)*").match("111").group() == "111"

# Test of fix re.fullmatch POSSESSIVE_REPEAT, issue #7183
assert re.fullmatch(r"([0-9]++(?:\.[0-9]+)*+)", "1.25.38")
assert re.fullmatch(r"([0-9]++(?:\.[0-9]+)*+)", "1.25.38").group(0) == "1.25.38"