add test for issue 104726

This commit is contained in:
The 8472 2022-11-22 20:54:10 +01:00
parent 66ccf36f16
commit d576a9b241

View File

@ -1631,6 +1631,18 @@ fn strslice_issue_16878() {
assert!(!"00abc01234567890123456789abc".contains("bcabc"));
}
#[test]
fn strslice_issue_104726() {
// Edge-case in the simd_contains impl.
// The first and last byte are the same so it backtracks by one byte
// which aligns with the end of the string. Previously incorrect offset calculations
// lead to out-of-bounds slicing.
#[rustfmt::skip]
let needle = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaba";
let haystack = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab";
assert!(!haystack.contains(needle));
}
#[test]
#[cfg_attr(miri, ignore)] // Miri is too slow
fn test_strslice_contains() {