mirror of
https://github.com/Shopify/liquid.git
synced 2025-07-29 00:00:29 -04:00
Compare commits
2 Commits
f5ed5404b5
...
3ac7e470e6
Author | SHA1 | Date | |
---|---|---|---|
|
3ac7e470e6 | ||
|
369a6c55e3 |
@ -15,6 +15,7 @@
|
||||
include: "Error in tag 'include' - Valid syntax: include '[template]' (with|for) [object|collection]"
|
||||
inline_comment_invalid: "Syntax error in tag '#' - Each line of comments must be prefixed by the '#' character"
|
||||
invalid_delimiter: "'%{tag}' is not a valid delimiter for %{block_name} tags. use %{block_delimiter}"
|
||||
invalid_template_encoding: "Invalid template encoding"
|
||||
render: "Syntax error in tag 'render' - Template name must be a quoted string"
|
||||
table_row: "Syntax Error in 'table_row loop' - Valid syntax: table_row [item] in [collection] cols=3"
|
||||
tag_never_closed: "'%{block_name}' tag was never closed"
|
||||
|
@ -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
|
||||
|
@ -337,4 +337,16 @@ class TemplateTest < Minitest::Test
|
||||
assert_equal("x=2", output)
|
||||
assert_instance_of(String, output)
|
||||
end
|
||||
|
||||
def test_raises_error_with_invalid_utf8
|
||||
e = assert_raises(SyntaxError) do
|
||||
Template.parse(<<~LIQUID)
|
||||
{% comment %}
|
||||
\xC0
|
||||
{% endcomment %}
|
||||
LIQUID
|
||||
end
|
||||
|
||||
assert_equal('Liquid syntax error: Invalid template encoding', e.message)
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user