diff --git a/lib/liquid/template.rb b/lib/liquid/template.rb index de06a6fa..3776415d 100644 --- a/lib/liquid/template.rb +++ b/lib/liquid/template.rb @@ -108,7 +108,7 @@ module Liquid 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 2ed1a6fa..08ec7648 100644 --- a/test/integration/template_test.rb +++ b/test/integration/template_test.rb @@ -349,4 +349,9 @@ class TemplateTest < Minitest::Test 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