Make sure the limit and offset values are integers

This commit is contained in:
David Cornu
2019-04-23 16:44:37 -04:00
parent c2ef247be5
commit 70ed1fc86d
2 changed files with 40 additions and 3 deletions
+12 -3
View File
@@ -124,14 +124,23 @@ module Liquid
from = if @from == :continue
offsets[@name].to_i
else
context.evaluate(@from).to_i
from_value = context.evaluate(@from)
if from_value.nil?
0
else
Utils.to_integer(from_value)
end
end
collection = context.evaluate(@collection_name)
collection = collection.to_a if collection.is_a?(Range)
limit = context.evaluate(@limit)
to = limit ? limit.to_i + from : nil
limit_value = context.evaluate(@limit)
to = if limit_value.nil?
nil
else
Utils.to_integer(limit_value) + from
end
segment = Utils.slice_collection(collection, from, to)
segment.reverse! if @reversed