Fix sort_natural on sorting with non-string values

This commit is contained in:
Eric Chan
2017-09-13 01:37:40 -04:00
parent 27c91203ab
commit 59950bff87
+10 -2
View File
@@ -143,11 +143,19 @@ module Liquid
ary = InputIterator.new(input)
if property.nil?
ary.sort { |a, b| a.casecmp(b) }
ary.sort { |a, b| a.to_s.casecmp(b.to_s) }
elsif ary.empty? # The next two cases assume a non-empty array.
[]
elsif ary.first.respond_to?(:[]) && !ary.first[property].nil?
ary.sort { |a, b| a[property].casecmp(b[property]) }
ary.sort do |a, b|
a = a[property]
b = b[property]
if a && b
a[property].to_s.casecmp(b[property].to_s)
else
a ? -1 : 1
end
end
end
end