mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-29 15:15:19 -07:00
Stringify properties before filtering (#1929)
This commit is contained in:
@@ -979,8 +979,10 @@ module Liquid
|
|||||||
attr_reader :context
|
attr_reader :context
|
||||||
|
|
||||||
def filter_array(input, property, target_value, default_value = [], &block)
|
def filter_array(input, property, target_value, default_value = [], &block)
|
||||||
ary = InputIterator.new(input, context)
|
property = Liquid::Utils.to_s(property)
|
||||||
|
return default_value if property.empty?
|
||||||
|
|
||||||
|
ary = InputIterator.new(input, context)
|
||||||
return default_value if ary.empty?
|
return default_value if ary.empty?
|
||||||
|
|
||||||
block.call(ary) do |item|
|
block.call(ary) do |item|
|
||||||
|
|||||||
@@ -1061,6 +1061,19 @@ class StandardFiltersTest < Minitest::Test
|
|||||||
assert_template_result(expected_output, template, { "array" => array })
|
assert_template_result(expected_output, template, { "array" => array })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_where_with_non_string_property
|
||||||
|
array = [
|
||||||
|
{ "handle" => "alpha", "{}" => true },
|
||||||
|
{ "handle" => "beta", "{}" => false },
|
||||||
|
{ "handle" => "gamma", "{}" => false },
|
||||||
|
{ "handle" => "delta", "{}" => true },
|
||||||
|
]
|
||||||
|
template = "{{ array | where: some_property, true | map: 'handle' | join: ' ' }}"
|
||||||
|
expected_output = "alpha delta"
|
||||||
|
|
||||||
|
assert_template_result(expected_output, template, { "array" => array, "some_property" => {} })
|
||||||
|
end
|
||||||
|
|
||||||
def test_where_string_keys
|
def test_where_string_keys
|
||||||
input = [
|
input = [
|
||||||
"alpha", "beta", "gamma", "delta"
|
"alpha", "beta", "gamma", "delta"
|
||||||
|
|||||||
Reference in New Issue
Block a user