From f5a20ff8e85b5238844f991714c2f51145585ac7 Mon Sep 17 00:00:00 2001 From: Dylan Smith Date: Thu, 21 Jun 2012 14:56:05 -0400 Subject: [PATCH] Fix a regression in tablerow limit parameter. I had accidentally read slice_collection_using_each as using to as an inclusive limit rather than exclusive, and no tests covered the offset or limit parameters. --- lib/liquid/htmltags.rb | 2 +- test/liquid/tags/html_tag_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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