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

Write one value at a time for array variables #1863

Merged
merged 2 commits into from
Dec 11, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions lib/liquid/variable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,21 @@ def render(context)

def render_to_output_buffer(context, output)
obj = render(context)
render_obj_to_output(obj, output)
output
end

if obj.is_a?(Array)
output << obj.join
elsif obj.nil?
else
def render_obj_to_output(obj, output)
case obj
when NilClass
# Do nothing
when Array
obj.each do |o|
render_obj_to_output(o, output)
end
when
output << obj.to_s
end

output
end

def disabled?(_context)
Expand Down
4 changes: 4 additions & 0 deletions test/integration/variable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ def test_render_symbol
assert_template_result('bar', '{{ foo }}', { 'foo' => :bar })
end

def test_nested_array
assert_template_result('', '{{ foo }}', { 'foo' => [[nil]] })
end

def test_dynamic_find_var
assert_template_result('bar', '{{ [key] }}', { 'key' => 'foo', 'foo' => 'bar' })
end
Expand Down
Loading