From 28aeba4b0a4bbdc6a03cda44144fdfde007eaf14 Mon Sep 17 00:00:00 2001 From: Kevin Ness Date: Sun, 31 May 2026 21:32:08 -0500 Subject: [PATCH] Fix bug in JsString ends_with --- core/string/src/lib.rs | 2 +- core/string/src/tests.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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)); +}