Merge pull request #1775 from Shopify/allow-nil-template-source

allow non-string template source
This commit is contained in:
Michael Go
2024-01-12 10:48:30 -04:00
committed by GitHub
3 changed files with 8 additions and 1 deletions
+1
View File
@@ -107,6 +107,7 @@ module Liquid
# Returns self for easy chaining
def parse(source, options = {})
parse_context = configure_options(options)
source = source.to_s.to_str
unless source.valid_encoding?
raise SyntaxError, parse_context.locale.t("errors.syntax.invalid_template_encoding")
+1 -1
View File
@@ -5,7 +5,7 @@ module Liquid
attr_reader :line_number, :for_liquid_tag
def initialize(source, line_numbers = false, line_number: nil, for_liquid_tag: false)
@source = source.to_s.to_str
@source = source
@line_number = line_number || (line_numbers ? 1 : nil)
@for_liquid_tag = for_liquid_tag
@offset = 0
+6
View File
@@ -349,4 +349,10 @@ class TemplateTest < Minitest::Test
assert_equal('Liquid syntax error: Invalid template encoding', e.message)
end
def test_allows_non_string_values_as_source
assert_equal('', Template.parse(nil).render)
assert_equal('1', Template.parse(1).render)
assert_equal('true', Template.parse(true).render)
end
end