From 730ad3684a0480c97d0c22a1f907d16215d82aee Mon Sep 17 00:00:00 2001 From: Michael Go Date: Wed, 10 Jan 2024 16:32:08 -0400 Subject: [PATCH] allow nil template source --- lib/liquid/template.rb | 2 +- test/integration/template_test.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/liquid/template.rb b/lib/liquid/template.rb index de06a6fa4..3776415d2 100644 --- a/lib/liquid/template.rb +++ b/lib/liquid/template.rb @@ -108,7 +108,7 @@ def initialize def parse(source, options = {}) parse_context = configure_options(options) - unless source.valid_encoding? + if source.is_a?(String) && !source.valid_encoding? raise SyntaxError, parse_context.locale.t("errors.syntax.invalid_template_encoding") end diff --git a/test/integration/template_test.rb b/test/integration/template_test.rb index 2ed1a6fa8..08ec76489 100644 --- a/test/integration/template_test.rb +++ b/test/integration/template_test.rb @@ -349,4 +349,9 @@ def test_raises_error_with_invalid_utf8 assert_equal('Liquid syntax error: Invalid template encoding', e.message) end + + def test_allows_nil_as_source + template = Template.parse(nil) + assert_equal('', template.render) + end end