diff --git a/core/string/src/lib.rs b/core/string/src/lib.rs index 1300ca055a7..633cbccb6d7 100644 --- a/core/string/src/lib.rs +++ b/core/string/src/lib.rs @@ -432,7 +432,7 @@ impl JsString { // We check the size, so this should never panic. #[allow(clippy::missing_panics_doc)] pub fn ends_with(&self, needle: JsStr<'_>) -> bool { - self.as_str().starts_with(needle) + self.as_str().ends_with(needle) } /// Get the `u16` code unit at index. This does not parse any characters if there diff --git a/core/string/src/tests.rs b/core/string/src/tests.rs index 43d0d3268d9..2315a558937 100644 --- a/core/string/src/tests.rs +++ b/core/string/src/tests.rs @@ -553,3 +553,15 @@ fn trim() { let base_str = JsString::from(" \u{000B} Hello World \t "); assert_eq!(base_str.trim(), JsString::from("Hello World")); } + +#[test] +fn starts_with_and_ends_with_basic() { + let basic = JsString::from("abcdef"); + let start_needle = JsStr::latin1("abc".as_bytes()); + assert!(basic.starts_with(start_needle)); + assert!(!basic.ends_with(start_needle)); + + let end_needle = JsStr::latin1("def".as_bytes()); + assert!(!basic.starts_with(end_needle)); + assert!(basic.ends_with(end_needle)); +}