diff --git a/lib/liquid/htmltags.rb b/lib/liquid/htmltags.rb index 33c85c04..78424e65 100644 --- a/lib/liquid/htmltags.rb +++ b/lib/liquid/htmltags.rb @@ -21,7 +21,7 @@ module Liquid collection = context[@collection_name] or return '' from = @attributes['offset'] ? context[@attributes['offset']].to_i : 0 - to = @attributes['limit'] ? from + context[@attributes['limit']].to_i - 1 : nil + to = @attributes['limit'] ? from + context[@attributes['limit']].to_i : nil collection = Utils.slice_collection_using_each(collection, from, to) diff --git a/test/liquid/tags/html_tag_test.rb b/test/liquid/tags/html_tag_test.rb index da02da6e..0815ba12 100644 --- a/test/liquid/tags/html_tag_test.rb +++ b/test/liquid/tags/html_tag_test.rb @@ -54,4 +54,10 @@ class HtmlTagTest < Test::Unit::TestCase '{% tablerow n in numbers cols:3%} {{n}} {% endtablerow %}', 'numbers' => ArrayDrop.new([1,2,3,4,5,6])) end + + def test_offset_and_limit + assert_template_result("\n 1 2 3 \n 4 5 6 \n", + '{% tablerow n in numbers cols:3 offset:1 limit:6%} {{n}} {% endtablerow %}', + 'numbers' => [0,1,2,3,4,5,6,7]) + end end # HtmlTagTest