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
10 changes: 5 additions & 5 deletions crates/sre_engine/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -998,12 +998,12 @@ fn search_info_literal<const LITERAL: bool, S: StrDrive>(
return true;
}

// `state.cursor` is `req.start + skip`, the position the
// tail match resumes from; advancing past the prefix
// instead would resume at `req.start + len` and only
// agree when the prefix ends at the skip boundary.
let mut next_ctx = ctx;
if skip != 0 {
next_ctx.advance_char::<S>();
} else {
next_ctx.cursor = state.cursor;
}
next_ctx.cursor = state.cursor;

if _match(req, state, next_ctx) {
return true;
Expand Down
15 changes: 15 additions & 0 deletions crates/sre_engine/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,19 @@ mod tests {
#[rustfmt::skip] let p = Pattern { pattern: "\u{e0}+", code: &[14, 4, 0, 1, 4294967295, 24, 6, 1, 4294967295, 16, 224, 1, 1] };
// END GENERATED
}

#[test]
fn search_literal_prefix_longer_than_skip() {
// The INFO block carries prefix_len=4 and prefix_skip=2, so the tail
// match has to resume at the skip boundary rather than past the whole
// prefix.
// pattern p = re.compile('ab(cd)')
// START GENERATED by generate_tests.py
#[rustfmt::skip] let p = Pattern { pattern: "ab(cd)", code: &[14, 14, 1, 4, 4, 4, 2, 97, 98, 99, 100, 0, 0, 0, 0, 16, 97, 16, 98, 17, 0, 16, 99, 16, 100, 17, 1, 1] };
// END GENERATED
let (req, mut state) = p.state("xabcdcd");
assert!(state.search(req));
assert_eq!(state.start, 1);
assert_eq!(state.cursor.position, 5);
}
}
Loading