Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow non-string template source #1775

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/liquid/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def initialize
# 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")
Expand Down
2 changes: 1 addition & 1 deletion lib/liquid/tokenizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Tokenizer
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
Expand Down
6 changes: 6 additions & 0 deletions test/integration/template_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,10 @@ def test_raises_error_with_invalid_utf8

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
Loading