Skip to content

Commit e9db8ad

Browse files
committed
core: Make TwoWaySearcher reset its prefix memory when shifting by byteset
Closes #16878.
1 parent 0bdac78 commit e9db8ad

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/libcore/str.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,9 @@ impl TwoWaySearcher {
479479
((haystack[self.position + needle.len() - 1] & 0x3f)
480480
as uint)) & 1 == 0 {
481481
self.position += needle.len();
482+
if !long_period {
483+
self.memory = 0;
484+
}
482485
continue 'search;
483486
}
484487

src/libcoretest/str.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ fn strslice_issue_16589() {
2626
check_contains_all_substrings("012345678901234567890123456789bcdabcdabcd");
2727
}
2828

29+
#[test]
30+
fn strslice_issue_16878() {
31+
assert!(!"1234567ah012345678901ah".contains("hah"));
32+
assert!(!"00abc01234567890123456789abc".contains("bcabc"));
33+
}
34+
2935

3036
#[test]
3137
fn test_strslice_contains() {

0 commit comments

Comments
 (0)