From 5e459b884a882c8e8e1e207376fcfbf589374d8f Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Tue, 10 Dec 2024 18:12:39 -0500 Subject: [PATCH 1/2] Write one value at a time for array variables --- lib/liquid/variable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/liquid/variable.rb b/lib/liquid/variable.rb index 372ee4dbf..1353ed182 100644 --- a/lib/liquid/variable.rb +++ b/lib/liquid/variable.rb @@ -97,7 +97,7 @@ def render_to_output_buffer(context, output) obj = render(context) if obj.is_a?(Array) - output << obj.join + obj.each { |o| output << o.to_s } elsif obj.nil? else output << obj.to_s From 820b238288a5f624dc20ed84c563842258ccb35d Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Tue, 10 Dec 2024 19:17:24 -0500 Subject: [PATCH 2/2] Handle recursive array --- lib/liquid/variable.rb | 18 ++++++++++++------ test/integration/variable_test.rb | 4 ++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/liquid/variable.rb b/lib/liquid/variable.rb index 1353ed182..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) - obj.each { |o| output << o.to_s } - 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