Fix the find filter to return nil when filtering empty arrays

This commit is contained in:
Guilherme Carreiro
2025-01-24 08:39:01 +01:00
committed by Guilherme Carreiro
parent b0dbc62696
commit 5718c4cee2
4 changed files with 25 additions and 4 deletions
+3 -3
View File
@@ -472,7 +472,7 @@ module Liquid
# @liquid_syntax array | find: string, string
# @liquid_return [untyped]
def find(input, property, target_value = nil)
filter_array(input, property, target_value) { |ary, &block| ary.find(&block) }
filter_array(input, property, target_value, nil) { |ary, &block| ary.find(&block) }
end
# @liquid_public_docs
@@ -969,10 +969,10 @@ module Liquid
attr_reader :context
def filter_array(input, property, target_value, &block)
def filter_array(input, property, target_value, default_value = [], &block)
ary = InputIterator.new(input, context)
return [] if ary.empty?
return default_value if ary.empty?
block.call(ary) do |item|
if target_value.nil?
+1 -1
View File
@@ -2,5 +2,5 @@
# frozen_string_literal: true
module Liquid
VERSION = "5.7.0"
VERSION = "5.7.1"
end