From 1bd307bb74dcccfb576dad5bfc901dd3065d6f17 Mon Sep 17 00:00:00 2001 From: sjh9714 <163989462+sjh9714@users.noreply.github.com> Date: Sun, 5 Jul 2026 09:21:27 +0900 Subject: [PATCH] Fix custom tag render result stringification --- lib/liquid/tag.rb | 5 ++++- test/integration/tag_test.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/liquid/tag.rb b/lib/liquid/tag.rb index 374ee511e..530cfbff2 100644 --- a/lib/liquid/tag.rb +++ b/lib/liquid/tag.rb @@ -58,7 +58,10 @@ def render(_context) # method will be removed. def render_to_output_buffer(context, output) render_result = render(context) - output << render_result if render_result + if render_result + render_result = render_result.join if render_result.is_a?(Array) + output << render_result.to_s + end output end diff --git a/test/integration/tag_test.rb b/test/integration/tag_test.rb index 6e28eb529..f0d745334 100644 --- a/test/integration/tag_test.rb +++ b/test/integration/tag_test.rb @@ -42,4 +42,30 @@ def render(*) assert_equal(buf.object_id, output.object_id) end end + + def test_custom_tags_stringify_render_result_for_backwards_compatibility + integer_tag = Class.new(Tag) do + def render(*) + 49 + end + end + + with_custom_tag('blabla', integer_tag) do + template = Liquid::Template.parse("{% blabla %}") + + assert_equal('49', template.render) + end + + array_tag = Class.new(Tag) do + def render(*) + [4, 9] + end + end + + with_custom_tag('blabla', array_tag) do + template = Liquid::Template.parse("{% blabla %}") + + assert_equal('49', template.render) + end + end end