Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/liquid/tags/table_row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def render_to_output_buffer(context, output)
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
Expand Down
14 changes: 14 additions & 0 deletions test/integration/tags/table_row_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ def test_blank_string_not_iterable
{ '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) %}
Expand Down