diff --git a/lib/liquid/parser.rb b/lib/liquid/parser.rb index 93cda908..645dfa3a 100644 --- a/lib/liquid/parser.rb +++ b/lib/liquid/parser.rb @@ -12,14 +12,6 @@ module Liquid @p = point end - def read(type = nil) - token = @tokens[@p] - if type && token[0] != type - raise SyntaxError, "Expected #{type} but found #{@tokens[@p].first}" - end - token[1] - end - def consume(type = nil) token = @tokens[@p] if type && token[0] != type diff --git a/lib/liquid/tags/render.rb b/lib/liquid/tags/render.rb index c337f4da..cabbfe2e 100644 --- a/lib/liquid/tags/render.rb +++ b/lib/liquid/tags/render.rb @@ -113,7 +113,7 @@ module Liquid return p.consume(:string) if p.look(:string) return p.consume(:id) if p.look(:id) - found = p.look(:end_of_string) ? "nothing" : p.read + found = p.consume || "nothing" raise SyntaxError, options[:locale].t("errors.syntax.render_invalid_template_name", found: found) end diff --git a/test/integration/tags/snippet_test.rb b/test/integration/tags/snippet_test.rb index 1476f9da..7a0383ad 100644 --- a/test/integration/tags/snippet_test.rb +++ b/test/integration/tags/snippet_test.rb @@ -953,6 +953,16 @@ class SnippetTest < Minitest::Test assert_match("Expected a string or identifier, found nothing", exception.message) end + + def test_render_with_invalid_identifier + 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 end class ResourceLimits < SnippetTest