Skip to content

Commit

Permalink
Handle recursive array
Browse files Browse the repository at this point in the history
  • Loading branch information
ianks committed Dec 11, 2024
1 parent 5e459b8 commit 820b238
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
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)
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)
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

0 comments on commit 820b238

Please sign in to comment.