Skip to content

Commit

Permalink
Reserve future support for comment line before a tag name
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanahsmith committed Feb 26, 2021
1 parent ab45548 commit 0fc45ca
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/liquid/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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"
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:
include: "Argument error in tag 'include' - Illegal template name"
disabled:
Expand Down
10 changes: 10 additions & 0 deletions lib/liquid/tags/inline_comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

module Liquid
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)
output
end
Expand Down
2 changes: 2 additions & 0 deletions test/integration/tags/inline_comment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ def test_tag_ws_stripping

def test_comment_inline_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
echo "ok" %}')
end
Expand Down

2 comments on commit 0fc45ca

@ADTC
Copy link
Contributor

@ADTC ADTC commented on 0fc45ca Feb 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer it to ignore everything including new lines until the next %}, thus making multi-line comments easy :) See #1393 (comment)

@dylanahsmith
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect the point of the comment is to comment on something, which I would expect to more often be the liquid code following it. That is what the test_comment_line_before_tag test is showing. Similarly, we might want to split long tag arguments onto multiple lines and comment on a specific argument, which means not ignoring everything that comes after it.

Please sign in to comment.