mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-20 11:20:41 -07:00
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:
@@ -51,7 +51,7 @@ module Liquid
|
|||||||
collection = Utils.slice_collection(collection, from, to)
|
collection = Utils.slice_collection(collection, from, to)
|
||||||
length = collection.length
|
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"
|
output << "<tr class=\"row1\">\n"
|
||||||
context.stack do
|
context.stack do
|
||||||
|
|||||||
@@ -66,6 +66,20 @@ class TableRowTest < Minitest::Test
|
|||||||
{ 'characters' => '' })
|
{ 'characters' => '' })
|
||||||
end
|
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
|
def test_tablerow_loop_drop_attributes
|
||||||
template = <<~LIQUID.chomp
|
template = <<~LIQUID.chomp
|
||||||
{% tablerow i in (1...2) %}
|
{% tablerow i in (1...2) %}
|
||||||
|
|||||||
Reference in New Issue
Block a user