Reserve future support for comment line before a tag name

This commit is contained in:
Dylan Thacker-Smith
2021-02-26 06:52:11 -05:00
parent ab455480fa
commit 0fc45ca3af
3 changed files with 13 additions and 0 deletions

View File

@@ -22,6 +22,7 @@
tag_never_closed: "'%{block_name}' tag was never closed" tag_never_closed: "'%{block_name}' tag was never closed"
table_row: "Syntax Error in 'table_row loop' - Valid syntax: table_row [item] in [collection] cols=3" table_row: "Syntax Error in 'table_row loop' - Valid syntax: table_row [item] in [collection] cols=3"
render: "Syntax error in tag 'render' - Template name must be a quoted string" render: "Syntax error in tag 'render' - Template name must be a quoted string"
inline_comment_invalid: "Syntax error in tag '#' - Each line of comments must be prefixed by the '#' character"
argument: argument:
include: "Argument error in tag 'include' - Illegal template name" include: "Argument error in tag 'include' - Illegal template name"
disabled: disabled:

View File

@@ -2,6 +2,16 @@
module Liquid module Liquid
class InlineComment < Tag class InlineComment < Tag
def initialize(tag_name, markup, options)
super
# Semantically, a comment should only ignore everything after it on the line.
# Currently, this implementation doesn't support mixing a comment with another tag
# but we need to reserve future support for this.
if markup.match?(/\n\s*[^#]/)
raise SyntaxError, options[:locale].t("errors.syntax.inline_comment_invalid")
end
end
def render_to_output_buffer(_context, output) def render_to_output_buffer(_context, output)
output output
end end

View File

@@ -26,7 +26,9 @@ class InlineCommentTest < Minitest::Test
def test_comment_inline_tag def test_comment_inline_tag
assert_template_result('ok', '{% echo "ok" # output something from a tag %}') assert_template_result('ok', '{% echo "ok" # output something from a tag %}')
end
def test_comment_line_before_tag
assert_template_result('ok', '{% # this sort of comment also assert_template_result('ok', '{% # this sort of comment also
echo "ok" %}') echo "ok" %}')
end end