@@ -387,6 +387,7 @@ def sort(input, property = nil)
387
387
end
388
388
elsif ary . all? { |el | el . respond_to? ( :[] ) }
389
389
begin
390
+ property = Utils . to_s ( property )
390
391
ary . sort { |a , b | nil_safe_compare ( a [ property ] , b [ property ] ) }
391
392
rescue TypeError
392
393
raise_property_error ( property )
@@ -416,6 +417,7 @@ def sort_natural(input, property = nil)
416
417
end
417
418
elsif ary . all? { |el | el . respond_to? ( :[] ) }
418
419
begin
420
+ property = Utils . to_s ( property )
419
421
ary . sort { |a , b | nil_safe_casecmp ( a [ property ] , b [ property ] ) }
420
422
rescue TypeError
421
423
raise_property_error ( property )
@@ -503,6 +505,7 @@ def uniq(input, property = nil)
503
505
elsif ary . empty? # The next two cases assume a non-empty array.
504
506
[ ]
505
507
else
508
+ property = Utils . to_s ( property )
506
509
ary . uniq do |item |
507
510
item [ property ]
508
511
rescue TypeError
@@ -534,6 +537,7 @@ def reverse(input)
534
537
# @liquid_syntax array | map: string
535
538
# @liquid_return [array[untyped]]
536
539
def map ( input , property )
540
+ property = Utils . to_s ( property )
537
541
InputIterator . new ( input , context ) . map do |e |
538
542
e = e . call if e . is_a? ( Proc )
539
543
@@ -563,6 +567,7 @@ def compact(input, property = nil)
563
567
elsif ary . empty? # The next two cases assume a non-empty array.
564
568
[ ]
565
569
else
570
+ property = Liquid ::Utils . to_s ( property )
566
571
ary . reject do |item |
567
572
item [ property ] . nil?
568
573
rescue TypeError
@@ -952,13 +957,13 @@ def default(input, default_value = '', options = {})
952
957
# @liquid_syntax array | sum
953
958
# @liquid_return [number]
954
959
def sum ( input , property = nil )
955
- property = Liquid ::Utils . to_s ( property )
960
+ property = Liquid ::Utils . to_s ( property ) unless property . nil? else property
956
961
957
962
ary = InputIterator . new ( input , context )
958
963
return 0 if ary . empty?
959
964
960
965
values_for_sum = ary . map do |item |
961
- if property . empty ?
966
+ if property . nil ?
962
967
item
963
968
elsif item . respond_to? ( :[] )
964
969
item [ property ]
0 commit comments