mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Raise syntax error on incorrect render identifier type
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
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"
|
||||
render_invalid_template_name: "Syntax error in tag 'render' - Expected a string or identifier, found %{found}"
|
||||
table_row: "Syntax Error in 'table_row loop' - Valid syntax: table_row [item] in [collection] cols=3"
|
||||
table_row_invalid_attribute: "Invalid attribute '%{attribute}' in tablerow loop. Valid attributes are cols, limit, offset, and range"
|
||||
tag_never_closed: "'%{block_name}' tag was never closed"
|
||||
|
||||
@@ -157,8 +157,10 @@ module Liquid
|
||||
|
||||
def rigid_template_name(p)
|
||||
return p.consume(:string) if p.look(:string)
|
||||
return p.consume(:id) if p.look(:id)
|
||||
|
||||
p.consume(:id) if p.look(:id)
|
||||
found = p.look(:end_of_string) ? "nothing" : p.read
|
||||
raise SyntaxError, options[:locale].t("errors.syntax.render_invalid_template_name", found: found)
|
||||
end
|
||||
|
||||
def strict_parse(markup)
|
||||
|
||||
@@ -1511,6 +1511,26 @@ class SnippetTest < Minitest::Test
|
||||
|
||||
assert_template_result(expected, template, error_mode: :rigid)
|
||||
end
|
||||
|
||||
def test_render_with_invalid_identifier_type
|
||||
template = "{% render 123 %}"
|
||||
|
||||
exception = assert_raises(SyntaxError) do
|
||||
Liquid::Template.parse(template, error_mode: :rigid)
|
||||
end
|
||||
|
||||
assert_match("Expected a string or identifier, found 123", exception.message)
|
||||
end
|
||||
|
||||
def test_render_with_no_identifier
|
||||
template = "{% render %}"
|
||||
|
||||
exception = assert_raises(SyntaxError) do
|
||||
Liquid::Template.parse(template, error_mode: :rigid)
|
||||
end
|
||||
|
||||
assert_match("Expected a string or identifier, found nothing", exception.message)
|
||||
end
|
||||
end
|
||||
|
||||
class ResourceLimits < SnippetTest
|
||||
|
||||
Reference in New Issue
Block a user