From 9e00efc8a57b43bf12022286155e77a1dd043bde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 8 Jul 2017 19:41:28 +0200 Subject: [PATCH] style: Make starts_with_ignore_ascii_case not lie if the strings are the same length. --- components/style/str.rs | 2 +- tests/unit/style/str.rs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/components/style/str.rs b/components/style/str.rs index 70fbe538533..92febb40824 100644 --- a/components/style/str.rs +++ b/components/style/str.rs @@ -148,6 +148,6 @@ pub fn str_join(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.len() >= prefix.len() && string.as_bytes()[0..prefix.len()].eq_ignore_ascii_case(prefix.as_bytes()) } diff --git a/tests/unit/style/str.rs b/tests/unit/style/str.rs index 439d32a5f10..154cf894158 100644 --- a/tests/unit/style/str.rs +++ b/tests/unit/style/str.rs @@ -34,6 +34,12 @@ pub fn test_str_join_many() { assert_eq!(actual, expected); } +#[test] +pub fn test_starts_with_ignore_ascii_case_basic() { + assert!(starts_with_ignore_ascii_case("-webkit-", "-webkit-")); + assert!(starts_with_ignore_ascii_case("-webkit-foo", "-webkit-")); +} + #[test] pub fn test_starts_with_ignore_ascii_case_char_boundary() { assert!(!starts_with_ignore_ascii_case("aaaaa💩", "-webkit-"));