From ade5de0ca5bd15c974cdca329051284cf0a1a022 Mon Sep 17 00:00:00 2001 From: Oskar Eichler Date: Sun, 30 Aug 2026 00:12:46 +0200 Subject: [PATCH] Handle empty by-function inputs --- lib/jmespath/nodes/function.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/jmespath/nodes/function.rb b/lib/jmespath/nodes/function.rb index 9d23e41..88c937c 100644 --- a/lib/jmespath/nodes/function.rb +++ b/lib/jmespath/nodes/function.rb @@ -474,8 +474,10 @@ def call(args) if get_type(args[0]) == ARRAY_TYPE && get_type(args[1]) == EXPRESSION_TYPE values = args[0].to_ary expression = args[1] + return [] if values.empty? + array_type = get_type(expression.eval(values[0])) - if array_type == STRING_TYPE || array_type == NUMBER_TYPE || values.empty? + if array_type == STRING_TYPE || array_type == NUMBER_TYPE # stable sort the list n = 0 values.sort_by do |value| @@ -509,6 +511,8 @@ def compare_by(mode, *args) expression = args[1] if get_type(values) == ARRAY_TYPE && get_type(expression) == EXPRESSION_TYPE values = values.to_ary + return nil if values.empty? + type = get_type(expression.eval(values.first)) if type != NUMBER_TYPE && type != STRING_TYPE msg = "function #{mode}() expects values to be strings or numbers"