check template UTF8 validity before parsing

This commit is contained in:
Michael Go
2024-01-10 18:58:15 +00:00
parent a3c837687e
commit 369a6c55e3
3 changed files with 18 additions and 0 deletions
+5
View File
@@ -107,6 +107,11 @@ module Liquid
# Returns self for easy chaining
def parse(source, options = {})
parse_context = configure_options(options)
unless source.valid_encoding?
raise SyntaxError, parse_context.locale.t("errors.syntax.invalid_template_encoding")
end
tokenizer = parse_context.new_tokenizer(source, start_line_number: @line_numbers && 1)
@root = Document.parse(tokenizer, parse_context)
self