diff --git a/lib/liquid/tags/for.rb b/lib/liquid/tags/for.rb index 2356b14..02ccc90 100644 --- a/lib/liquid/tags/for.rb +++ b/lib/liquid/tags/for.rb @@ -129,7 +129,7 @@ module Liquid end collection = context.evaluate(@collection_name) - collection = collection.to_a if collection.is_a?(Range) + collection = collection.step(1).to_a if collection.is_a?(Range) limit = context.evaluate(@limit) to = limit ? limit.to_i + from : nil diff --git a/test/integration/tags/for_tag_test.rb b/test/integration/tags/for_tag_test.rb index d9d396f..5f4aebe 100644 --- a/test/integration/tags/for_tag_test.rb +++ b/test/integration/tags/for_tag_test.rb @@ -48,6 +48,10 @@ HERE def test_for_with_variable_range assert_template_result(' 1 2 3 ', '{%for item in (1..foobar) %} {{item}} {%endfor%}', "foobar" => 3) + assert_template_result(' 1.0 2.0 3.0 ', '{%for item in foobar %} {{item}} {%endfor%}', "foobar" => (1..3.0)) + assert_template_result(' 1.0 2.0 3.0 ', '{%for item in foobar %} {{item}} {%endfor%}', "foobar" => (1.0..3)) + assert_template_result(' 1.0 2.0 3.0 ', '{%for item in foobar %} {{item}} {%endfor%}', "foobar" => (1.0..3.0)) + assert_template_result(' 1.5 2.5 ', '{%for item in foobar %} {{item}} {%endfor%}', "foobar" => (1.5..3)) end def test_for_with_hash_value_range