mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 17:15:12 -07:00
Add param to accept invalid input in to_integer
This commit is contained in:
@@ -16,8 +16,8 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def evaluate(context)
|
def evaluate(context)
|
||||||
start_int = Utils.to_integer(context.evaluate(@start_obj))
|
start_int = Utils.to_integer(context.evaluate(@start_obj), true)
|
||||||
end_int = Utils.to_integer(context.evaluate(@end_obj))
|
end_int = Utils.to_integer(context.evaluate(@end_obj), true)
|
||||||
start_int..end_int
|
start_int..end_int
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+3
-2
@@ -33,13 +33,14 @@ module Liquid
|
|||||||
segments
|
segments
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.to_integer(num)
|
def self.to_integer(num, accept_invalid = false)
|
||||||
return num if num.is_a?(Integer)
|
return num if num.is_a?(Integer)
|
||||||
num = num.to_s
|
num = num.to_s
|
||||||
begin
|
begin
|
||||||
Integer(num)
|
Integer(num)
|
||||||
rescue ::ArgumentError
|
rescue ::ArgumentError
|
||||||
raise Liquid::ArgumentError, "invalid integer"
|
raise Liquid::ArgumentError, "invalid integer" unless accept_invalid
|
||||||
|
0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user