mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-17 01:40:42 -07:00
Fix regression when using empty/nil properties with array filters (#1944)
* Make all array filters that use `filter_array` util process empty string and nil correctly * up version * fix ordering of checks * also do it for map * Do not raise property error * Gracefully empty property in map filter --------- Co-authored-by: Marco Concetto Rudilosso <[email protected]>
This commit is contained in:
co-authored by
Marco Concetto Rudilosso
parent
87bc6e7cfa
commit
2b75bfaff4
@@ -3,7 +3,6 @@
|
||||
require 'cgi'
|
||||
require 'base64'
|
||||
require 'bigdecimal'
|
||||
|
||||
module Liquid
|
||||
module StandardFilters
|
||||
MAX_I32 = (1 << 31) - 1
|
||||
@@ -538,6 +537,10 @@ module Liquid
|
||||
# @liquid_return [array[untyped]]
|
||||
def map(input, property)
|
||||
property = Utils.to_s(property)
|
||||
|
||||
# Return the input array if property is empty (no-op)
|
||||
return InputIterator.new(input, context).to_a if property.empty?
|
||||
|
||||
InputIterator.new(input, context).map do |e|
|
||||
e = e.call if e.is_a?(Proc)
|
||||
|
||||
@@ -986,12 +989,11 @@ module Liquid
|
||||
attr_reader :context
|
||||
|
||||
def filter_array(input, property, target_value, default_value = [], &block)
|
||||
property = Liquid::Utils.to_s(property)
|
||||
return default_value if property.empty?
|
||||
|
||||
ary = InputIterator.new(input, context)
|
||||
return default_value if ary.empty?
|
||||
|
||||
property = Utils.to_s(property)
|
||||
|
||||
block.call(ary) do |item|
|
||||
if target_value.nil?
|
||||
item[property]
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Liquid
|
||||
VERSION = "5.8.2"
|
||||
VERSION = "5.8.3"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user