Write one value at a time for array variables (#1863)

* Write one value at a time for array variables

* Handle recursive array
This commit is contained in:
Ian Ker-Seymer
2024-12-11 10:16:58 -05:00
committed by GitHub
parent 9a06cedbba
commit 63583ffe5b
2 changed files with 16 additions and 6 deletions
+12 -6
View File
@@ -95,15 +95,21 @@ module Liquid
def render_to_output_buffer(context, output) def render_to_output_buffer(context, output)
obj = render(context) obj = render(context)
render_obj_to_output(obj, output)
output
end
if obj.is_a?(Array) def render_obj_to_output(obj, output)
output << obj.join case obj
elsif obj.nil? when NilClass
else # Do nothing
when Array
obj.each do |o|
render_obj_to_output(o, output)
end
when
output << obj.to_s output << obj.to_s
end end
output
end end
def disabled?(_context) def disabled?(_context)
+4
View File
@@ -130,6 +130,10 @@ class VariableTest < Minitest::Test
assert_template_result('bar', '{{ foo }}', { 'foo' => :bar }) assert_template_result('bar', '{{ foo }}', { 'foo' => :bar })
end end
def test_nested_array
assert_template_result('', '{{ foo }}', { 'foo' => [[nil]] })
end
def test_dynamic_find_var def test_dynamic_find_var
assert_template_result('bar', '{{ [key] }}', { 'key' => 'foo', 'foo' => 'bar' }) assert_template_result('bar', '{{ [key] }}', { 'key' => 'foo', 'foo' => 'bar' })
end end