Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/jmespath/nodes/function.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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"
Expand Down