From 982b2d8adf8f3daeac76eae8b56081f078910537 Mon Sep 17 00:00:00 2001 From: benonymus Date: Mon, 27 Apr 2026 14:15:56 +0700 Subject: [PATCH 1/2] Handle nil input in split --- lib/expression/callbacks/standard.ex | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/expression/callbacks/standard.ex b/lib/expression/callbacks/standard.ex index 52cf8347..ce877c71 100644 --- a/lib/expression/callbacks/standard.ex +++ b/lib/expression/callbacks/standard.ex @@ -1177,6 +1177,7 @@ defmodule Expression.Callbacks.Standard do Defaults to split the string using a space. """ @expression_category "string" + @expression_doc expression: "split(nil)", result: [] @expression_doc expression: "split(\"testing something\")", result: ["testing", "something"] @expression_doc expression: "split(\"testing something\", \"e\")", result: ["t", "sting som", "thing"] @@ -1205,12 +1206,26 @@ defmodule Expression.Callbacks.Standard do } }, result: ["t", "sting som", "thing"] - def split(ctx, binary), - do: String.split(eval!(binary, ctx), " ") + def split(ctx, binary) do + text = eval!(binary, ctx) + + if is_nil(text) do + [] + else + String.split(eval!(binary, ctx), " ") + end + end @expression_category "string" - def split(ctx, binary, pattern), - do: String.split(eval!(binary, ctx), eval!(pattern, ctx)) + def split(ctx, binary, pattern) do + text = eval!(binary, ctx) + + if is_nil(text) do + [] + else + String.split(eval!(binary, ctx), eval!(pattern, ctx)) + end + end @doc """ Returns the sum of all arguments, equivalent to the + operator From 69925e8756363f2c2fbb2ae8de46f044a8cb233a Mon Sep 17 00:00:00 2001 From: benonymus Date: Mon, 27 Apr 2026 14:30:30 +0700 Subject: [PATCH 2/2] Update standard.ex --- lib/expression/callbacks/standard.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/expression/callbacks/standard.ex b/lib/expression/callbacks/standard.ex index ce877c71..495bb10e 100644 --- a/lib/expression/callbacks/standard.ex +++ b/lib/expression/callbacks/standard.ex @@ -1212,7 +1212,7 @@ defmodule Expression.Callbacks.Standard do if is_nil(text) do [] else - String.split(eval!(binary, ctx), " ") + String.split(text, " ") end end @@ -1223,7 +1223,7 @@ defmodule Expression.Callbacks.Standard do if is_nil(text) do [] else - String.split(eval!(binary, ctx), eval!(pattern, ctx)) + String.split(text, eval!(pattern, ctx)) end end