From 820b238288a5f624dc20ed84c563842258ccb35d Mon Sep 17 00:00:00 2001 From: Ian Ker-Seymer Date: Tue, 10 Dec 2024 19:17:24 -0500 Subject: [PATCH] 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 1353ed18..2bcf871e 100644 --- a/lib/liquid/variable.rb +++ b/lib/liquid/variable.rb @@ -95,15 +95,21 @@ module Liquid 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 22f2b64e..19922c19 100644 --- a/test/integration/variable_test.rb +++ b/test/integration/variable_test.rb @@ -130,6 +130,10 @@ class VariableTest < Minitest::Test 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