tablerow: Avoid accidental special case for constant nil cols (#1644)

It should behave the same as an expression that evaluates to nil
This commit is contained in:
Dylan Thacker-Smith
2022-10-25 10:21:03 -04:00
committed by GitHub
parent c99c93255d
commit 6ce4ec1011
2 changed files with 15 additions and 1 deletions
+1 -1
View File
@@ -51,7 +51,7 @@ module Liquid
collection = Utils.slice_collection(collection, from, to)
length = collection.length
cols = @attributes['cols'].nil? ? length : context.evaluate(@attributes['cols']).to_i
cols = @attributes.key?('cols') ? context.evaluate(@attributes['cols']).to_i : length
output << "<tr class=\"row1\">\n"
context.stack do
+14
View File
@@ -66,6 +66,20 @@ class TableRowTest < Minitest::Test
{ 'characters' => '' })
end
def test_cols_nil_constant_same_as_evaluated_nil_expression
expect = "<tr class=\"row1\">\n" \
"<td class=\"col1\">false</td>" \
"<td class=\"col2\">false</td>" \
"</tr>\n"
assert_template_result(expect,
"{% tablerow i in (1..2) cols:nil %}{{ tablerowloop.col_last }}{% endtablerow %}")
assert_template_result(expect,
"{% tablerow i in (1..2) cols:var %}{{ tablerowloop.col_last }}{% endtablerow %}",
{ "var" => nil })
end
def test_tablerow_loop_drop_attributes
template = <<~LIQUID.chomp
{% tablerow i in (1...2) %}