From 3556c3371ef923c778b0936d451dea33f8d1a20c Mon Sep 17 00:00:00 2001 From: Julia Boutin Date: Tue, 21 Oct 2025 21:08:35 -0600 Subject: [PATCH] Raise syntax error on incorrect render identifier type --- lib/liquid/locales/en.yml | 1 + lib/liquid/tags/render.rb | 4 +++- test/integration/tags/snippet_test.rb | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/liquid/locales/en.yml b/lib/liquid/locales/en.yml index 6cff46a7..31eec5fd 100644 --- a/lib/liquid/locales/en.yml +++ b/lib/liquid/locales/en.yml @@ -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" diff --git a/lib/liquid/tags/render.rb b/lib/liquid/tags/render.rb index 177c8f4d..a6fd0c48 100644 --- a/lib/liquid/tags/render.rb +++ b/lib/liquid/tags/render.rb @@ -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) diff --git a/test/integration/tags/snippet_test.rb b/test/integration/tags/snippet_test.rb index 8830285a..18b41ad4 100644 --- a/test/integration/tags/snippet_test.rb +++ b/test/integration/tags/snippet_test.rb @@ -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