diff --git a/lib/liquid/variable.rb b/lib/liquid/variable.rb index 372ee4dbf..2bcf871ea 100644 --- a/lib/liquid/variable.rb +++ b/lib/liquid/variable.rb @@ -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) diff --git a/test/integration/variable_test.rb b/test/integration/variable_test.rb index 22f2b64e8..19922c191 100644 --- a/test/integration/variable_test.rb +++ b/test/integration/variable_test.rb @@ -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