diff --git a/src/libcore/str.rs b/src/libcore/str.rs index b067e6299ee..c8325fbcd80 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -479,6 +479,9 @@ impl TwoWaySearcher { ((haystack[self.position + needle.len() - 1] & 0x3f) as uint)) & 1 == 0 { self.position += needle.len(); + if !long_period { + self.memory = 0; + } continue 'search; } diff --git a/src/libcoretest/str.rs b/src/libcoretest/str.rs index be2275dcd4a..51bd72ec014 100644 --- a/src/libcoretest/str.rs +++ b/src/libcoretest/str.rs @@ -26,6 +26,12 @@ fn strslice_issue_16589() { check_contains_all_substrings("012345678901234567890123456789bcdabcdabcd"); } +#[test] +fn strslice_issue_16878() { + assert!(!"1234567ah012345678901ah".contains("hah")); + assert!(!"00abc01234567890123456789abc".contains("bcabc")); +} + #[test] fn test_strslice_contains() {