mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-26 13:45:13 -07:00
Merge pull request #620 from Shopify/accept-invalid-range-args
Add param to accept invalid input in to_integer
This commit is contained in:
@@ -16,9 +16,22 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def evaluate(context)
|
def evaluate(context)
|
||||||
start_int = Utils.to_integer(context.evaluate(@start_obj))
|
start_int = to_integer(context.evaluate(@start_obj))
|
||||||
end_int = Utils.to_integer(context.evaluate(@end_obj))
|
end_int = to_integer(context.evaluate(@end_obj))
|
||||||
start_int..end_int
|
start_int..end_int
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def to_integer(input)
|
||||||
|
case input
|
||||||
|
when Integer
|
||||||
|
input
|
||||||
|
when NilClass, String
|
||||||
|
input.to_i
|
||||||
|
else
|
||||||
|
Utils.to_integer(input)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ HERE
|
|||||||
assert_raises(Liquid::ArgumentError) do
|
assert_raises(Liquid::ArgumentError) do
|
||||||
Template.parse('{% for i in (a..2) %}{% endfor %}').render!("a" => [1, 2])
|
Template.parse('{% for i in (a..2) %}{% endfor %}').render!("a" => [1, 2])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
assert_template_result(' 0 1 2 3 ', '{% for item in (a..3) %} {{item}} {% endfor %}', "a" => "invalid integer")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_for_with_variable_range
|
def test_for_with_variable_range
|
||||||
|
|||||||
Reference in New Issue
Block a user