Skip to content

Commit d576a9b

Browse files
committed
add test for issue 104726
1 parent 66ccf36 commit d576a9b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

library/alloc/tests/str.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1631,6 +1631,18 @@ fn strslice_issue_16878() {
16311631
assert!(!"00abc01234567890123456789abc".contains("bcabc"));
16321632
}
16331633

1634+
#[test]
1635+
fn strslice_issue_104726() {
1636+
// Edge-case in the simd_contains impl.
1637+
// The first and last byte are the same so it backtracks by one byte
1638+
// which aligns with the end of the string. Previously incorrect offset calculations
1639+
// lead to out-of-bounds slicing.
1640+
#[rustfmt::skip]
1641+
let needle = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaba";
1642+
let haystack = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab";
1643+
assert!(!haystack.contains(needle));
1644+
}
1645+
16341646
#[test]
16351647
#[cfg_attr(miri, ignore)] // Miri is too slow
16361648
fn test_strslice_contains() {

0 commit comments

Comments
 (0)