Skip to content

Commit 2b45363

Browse files
committed
always stringify properties in all array filters
1 parent 88a38e3 commit 2b45363

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/liquid/standardfilters.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ def sort(input, property = nil)
387387
end
388388
elsif ary.all? { |el| el.respond_to?(:[]) }
389389
begin
390+
property = Utils.to_s(property)
390391
ary.sort { |a, b| nil_safe_compare(a[property], b[property]) }
391392
rescue TypeError
392393
raise_property_error(property)
@@ -416,6 +417,7 @@ def sort_natural(input, property = nil)
416417
end
417418
elsif ary.all? { |el| el.respond_to?(:[]) }
418419
begin
420+
property = Utils.to_s(property)
419421
ary.sort { |a, b| nil_safe_casecmp(a[property], b[property]) }
420422
rescue TypeError
421423
raise_property_error(property)
@@ -503,6 +505,7 @@ def uniq(input, property = nil)
503505
elsif ary.empty? # The next two cases assume a non-empty array.
504506
[]
505507
else
508+
property = Utils.to_s(property)
506509
ary.uniq do |item|
507510
item[property]
508511
rescue TypeError
@@ -534,6 +537,7 @@ def reverse(input)
534537
# @liquid_syntax array | map: string
535538
# @liquid_return [array[untyped]]
536539
def map(input, property)
540+
property = Utils.to_s(property)
537541
InputIterator.new(input, context).map do |e|
538542
e = e.call if e.is_a?(Proc)
539543

@@ -563,6 +567,7 @@ def compact(input, property = nil)
563567
elsif ary.empty? # The next two cases assume a non-empty array.
564568
[]
565569
else
570+
property = Liquid::Utils.to_s(property)
566571
ary.reject do |item|
567572
item[property].nil?
568573
rescue TypeError
@@ -952,13 +957,13 @@ def default(input, default_value = '', options = {})
952957
# @liquid_syntax array | sum
953958
# @liquid_return [number]
954959
def sum(input, property = nil)
955-
property = Liquid::Utils.to_s(property)
960+
property = Liquid::Utils.to_s(property) unless property.nil? else property
956961

957962
ary = InputIterator.new(input, context)
958963
return 0 if ary.empty?
959964

960965
values_for_sum = ary.map do |item|
961-
if property.empty?
966+
if property.nil?
962967
item
963968
elsif item.respond_to?(:[])
964969
item[property]

0 commit comments

Comments
 (0)