From c69828fd874fa33348a69cddc564197aad18691b Mon Sep 17 00:00:00 2001 From: Dmitry Dodzin Date: Sat, 8 Nov 2025 15:39:49 +0200 Subject: [PATCH] Update so split function will not return "ends" when passing empty pattern --- src/context/builtins.rs | 10 ++++++++++ src/lib.rs | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/context/builtins.rs b/src/context/builtins.rs index 3825de4..d7b4834 100644 --- a/src/context/builtins.rs +++ b/src/context/builtins.rs @@ -409,6 +409,16 @@ pub fn capture(input: &Value, re: &Value) -> Result { pub fn split(value: &Value, re: &Value) -> Result { match (value, re) { (Value::Null, _) => Ok(Value::Null), + + (Value::String(value), Value::String(empty)) if empty.is_empty() => Ok(Value::Array( + value + .split("") + .skip(1) // custom case where the patten is empty to match java behaviour + .take(value.len()) + .map(str::to_owned) + .map(Value::String) + .collect(), + )), (Value::String(value), Value::String(re)) => { let re = Regex::new(re).map_err(|err| { JsltError::RuntimeError(format!("Unexpected error when parsing re: {err}")) diff --git a/src/lib.rs b/src/lib.rs index 363d965..683dd52 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -779,7 +779,7 @@ mod tests { #[case("1,2,3,4,5".into(), ";".into(), r#"["1,2,3,4,5"]"#)] #[case("null", ";".into(), "null")] #[case(",2".into(), ",".into(), r#"["", "2"]"#)] - // #[case("2,".into(), ",".into(), r#"["2"]"#)] TODO: maybe add the logic + #[case("22".into(), "".into(), r#"["2", "2"]"#)] fn function_split( #[case] left: Value, #[case] right: Value,