Raise syntax error on incorrect render identifier type

This commit is contained in:
Julia Boutin
2025-10-27 10:13:04 -06:00
parent 96a44927b5
commit 3556c3371e
3 changed files with 24 additions and 1 deletions
+1
View File
@@ -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"
+3 -1
View File
@@ -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)
+20
View File
@@ -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