dont explode when sorting nil property

This commit is contained in:
Richard Monette
2016-10-04 13:22:29 -04:00
parent 64fca66ef5
commit bb3624b799
2 changed files with 27 additions and 1 deletions
+9 -1
View File
@@ -125,7 +125,15 @@ module Liquid
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] <=> b[property] }
ary.sort do |a, b|
a = a[property]
b = b[property]
if a && b
a <=> b
else
a ? -1 : 1
end
end
end
end