raise invalid integer argument error from tablerow

This commit is contained in:
Michael Go
2023-01-16 18:53:53 -04:00
parent e804f36681
commit 0f11c97623
3 changed files with 64 additions and 4 deletions
+14 -3
View File
@@ -45,13 +45,24 @@ module Liquid
def render_to_output_buffer(context, output)
(collection = context.evaluate(@collection_name)) || (return '')
from = @attributes.key?('offset') ? context.evaluate(@attributes['offset']).to_i : 0
to = @attributes.key?('limit') ? from + context.evaluate(@attributes['limit']).to_i : nil
from = if @attributes.key?('offset')
Utils.to_integer(context.evaluate(@attributes['offset']), allow_nil: true)
else
0
end
to = if @attributes.key?('limit')
from + Utils.to_integer(context.evaluate(@attributes['limit']), allow_nil: true)
end
collection = Utils.slice_collection(collection, from, to)
length = collection.length
cols = @attributes.key?('cols') ? context.evaluate(@attributes['cols']).to_i : length
cols = if @attributes.key?('cols')
Utils.to_integer(context.evaluate(@attributes['cols']), allow_nil: true)
else
length
end
output << "<tr class=\"row1\">\n"
context.stack do
+4 -1
View File
@@ -39,8 +39,11 @@ module Liquid
segments
end
def self.to_integer(num)
def self.to_integer(num, allow_nil: false)
return num if num.is_a?(Integer)
# with allow_nil param, return 0 which is equal to nil.to_i
return 0 if num.nil? && allow_nil
num = num.to_s
begin
Integer(num)