style: Fix starts_with_ignore_ascii_case.

In particular, fix a panic when the input is not ASCII and we happen to index in
something that is not a char boundary.

This fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1379380
This commit is contained in:
Emilio Cobos Álvarez 2017-07-08 19:29:08 +02:00
parent 1425ad1bab
commit d8a22d8bd7
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
2 changed files with 7 additions and 2 deletions

View file

@ -149,5 +149,5 @@ pub fn str_join<I, T>(strs: I, join: &str) -> String
/// Returns true if a given string has a given prefix with case-insensitive match.
pub fn starts_with_ignore_ascii_case(string: &str, prefix: &str) -> bool {
string.len() > prefix.len() &&
string[0..prefix.len()].eq_ignore_ascii_case(prefix)
string.as_bytes()[0..prefix.len()].eq_ignore_ascii_case(prefix.as_bytes())
}