Skip to content

Fix starts_with() and ends_with(). #9924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2013

Conversation

metajack
Copy link
Contributor

d4a3238 broke these since slice_to() and slice_from() must get character
boundaries, and arbitrary needle lengths don't necessarily map to character
boundaries of the haystack.

This also adds new tests that would have caught this bug.

}

#[inline]
fn ends_with(&self, needle: &str) -> bool {
let (m, n) = (self.len(), needle.len());
m >= n && needle == self.slice_from(m - n)
m >= n && needle.as_bytes() == self.as_bytes().pslice_from(m - n)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wtf? i must have hit Ctrl-t after i ran tests. Fixing.

Verified

This commit was signed with the committer’s verified signature.
pietroalbini Pietro Albini
d4a3238 broke these since slice_to() and slice_from() must get character
boundaries, and arbitrary needle lengths don't necessarily map to character
boundaries of the haystack.

This also adds new tests that would have caught this bug.
bors added a commit that referenced this pull request Oct 18, 2013

Verified

This commit was signed with the committer’s verified signature.
pietroalbini Pietro Albini
d4a3238 broke these since slice_to() and slice_from() must get character
boundaries, and arbitrary needle lengths don't necessarily map to character
boundaries of the haystack.

This also adds new tests that would have caught this bug.
@bors bors closed this Oct 18, 2013
@bors bors merged commit 090b245 into rust-lang:master Oct 18, 2013
flip1995 pushed a commit to flip1995/rust that referenced this pull request Dec 1, 2022

Verified

This commit was signed with the committer’s verified signature.
pietroalbini Pietro Albini
Add `clippy_utils::msrv::Msrv` to keep track of the current MSRV

changelog: Fix the scoping of the `#![clippy::msrv]` attribute

Fixes rust-lang#6920

r? `@Jarcho`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants