From f484b868d08c8153fc397f28e7be193f2dcdf3ff Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Fri, 28 Oct 2022 13:55:33 -0400 Subject: [PATCH 1/2] assert_template_result: Avoid using the BlankFileSystem Since it doesn't reflect the real liquid usage that we are trying to test against. --- test/test_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 23f0a42a..2caa7b32 100755 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -42,7 +42,7 @@ module Minitest message: nil, partials: nil, error_mode: nil, render_errors: false ) template = Liquid::Template.parse(template, line_numbers: true, error_mode: error_mode&.to_sym) - file_system = StubFileSystem.new(partials) if partials + file_system = StubFileSystem.new(partials || {}) registers = Liquid::Registers.new(file_system: file_system) context = Liquid::Context.build(environments: assigns, rethrow_errors: !render_errors, registers: registers) output = template.render(context) From db8e85ab31e17c4de00a79f919e8b53da5aa7699 Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Fri, 28 Oct 2022 13:57:17 -0400 Subject: [PATCH 2/2] Prevent an internal error in include tag from non-string template_name which would otherwise happen on `template_name.split('/')` --- lib/liquid/tags/include.rb | 2 +- test/integration/tags/include_tag_test.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/liquid/tags/include.rb b/lib/liquid/tags/include.rb index 3fdc8429..0664f5c3 100644 --- a/lib/liquid/tags/include.rb +++ b/lib/liquid/tags/include.rb @@ -52,7 +52,7 @@ module Liquid def render_to_output_buffer(context, output) template_name = context.evaluate(@template_name_expr) - raise ArgumentError, options[:locale].t("errors.argument.include") unless template_name + raise ArgumentError, options[:locale].t("errors.argument.include") unless template_name.is_a?(String) partial = PartialCache.load( template_name, diff --git a/test/integration/tags/include_tag_test.rb b/test/integration/tags/include_tag_test.rb index 10385157..91f1aeab 100644 --- a/test/integration/tags/include_tag_test.rb +++ b/test/integration/tags/include_tag_test.rb @@ -249,6 +249,11 @@ class IncludeTagTest < Minitest::Test "{% include nil %}", render_errors: true) end + def test_render_raise_argument_error_when_template_is_not_a_string + assert_template_result("Liquid error (line 1): Argument error in tag 'include' - Illegal template name", + "{% include 123 %}", render_errors: true) + end + def test_including_via_variable_value assert_template_result("from TestFileSystem", "{% assign page = 'pick_a_source' %}{% include page %}", partials: { "pick_a_source" => "from TestFileSystem" })