mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-15 00:40:40 -07:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a7ad5f4282 | ||
|
|
2998ae38ba | ||
|
|
09f9a87ea3 | ||
|
|
035a0db6ab |
@@ -3,7 +3,6 @@
|
||||
require 'cgi'
|
||||
require 'base64'
|
||||
require 'bigdecimal'
|
||||
|
||||
module Liquid
|
||||
module StandardFilters
|
||||
MAX_I32 = (1 << 31) - 1
|
||||
@@ -537,6 +536,10 @@ module Liquid
|
||||
# @liquid_syntax array | map: string
|
||||
# @liquid_return [array[untyped]]
|
||||
def map(input, property)
|
||||
if property.nil?
|
||||
raise_property_error(property)
|
||||
end
|
||||
|
||||
property = Utils.to_s(property)
|
||||
InputIterator.new(input, context).map do |e|
|
||||
e = e.call if e.is_a?(Proc)
|
||||
@@ -986,12 +989,15 @@ 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?
|
||||
|
||||
if property.nil?
|
||||
raise_property_error(property)
|
||||
end
|
||||
|
||||
property = Liquid::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
|
||||
|
||||
@@ -1033,6 +1033,24 @@ class StandardFiltersTest < Minitest::Test
|
||||
assert_template_result(expected_output, template, { "array" => array })
|
||||
end
|
||||
|
||||
def test_where_with_empty_string_and_nil
|
||||
array = [
|
||||
"alpha",
|
||||
"beta",
|
||||
"gamma",
|
||||
]
|
||||
template = "{{ array | where: '' | join: ' ' }}"
|
||||
expected_output = "alpha beta gamma"
|
||||
assert_template_result(expected_output, template, { "array" => array })
|
||||
|
||||
template = "{{ array | where: nil | join: ' ' }}"
|
||||
exception = assert_raises(Liquid::ArgumentError) do
|
||||
assert_template_result(expected_output, template, { "array" => array })
|
||||
end
|
||||
|
||||
assert_equal("Liquid error (line 1): cannot select the property ''", exception.message)
|
||||
end
|
||||
|
||||
def test_where_with_value
|
||||
array = [
|
||||
{ "handle" => "alpha", "ok" => true },
|
||||
|
||||
Reference in New Issue
Block a user