Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #411 - cite-reader:hyphen-doesnt-panic, r=kbknapp
fix: Stop lonely hyphens from causing panic The method `starts_with` as implemented for the `OsStrExt2` trait on `OsStr` assumed that the needle given is shorter than the haystack. When this is not the case, the method panics due to an attempted out-of-bounds access on the byte representation of `self`. Problematic if, say, an end-user gives us `"-"` and the library tries to see if that starts with `"--"`. Fortunately, slices already implement a `starts_with` method, and we can delegate to it. This *does* create a semantics change: if both `self` and the needle have length 0, this implementation will return `true`, but the old implementation would return `false`. Based on the test suite still passing, acknowledging the vacuous truth doesn't seem to cause any problems. Fixes #410
- Loading branch information