diff --git a/rust/src/text/src/output/decoded.rs b/rust/src/text/src/output/decoded.rs index 6452d66b6c..5b96005860 100644 --- a/rust/src/text/src/output/decoded.rs +++ b/rust/src/text/src/output/decoded.rs @@ -309,7 +309,7 @@ fn matches_stop_string(stops: &[String], output: &str, new_bytes: usize) -> Opti .find_map(|(ss_idx, (ss, len, start_off))| { output[start_off..] .windows(len) - .rposition(|w| w == ss) + .position(|w| w == ss) .map(|pos| (ss_idx, start_off + pos)) }) } @@ -562,6 +562,13 @@ mod tests { assert_eq!(result, Some((0, 4))); } + #[test] + fn stop_string_matches_leftmost_with_multiple_new_bytes() { + let stops = vec!["\n".to_string()]; + let result = matches_stop_string(&stops, "Answer\n\n", 2); + assert_eq!(result, Some((0, 6))); + } + #[test] fn stop_string_matches_at_beginning() { let stops = vec!["say".to_string()];