-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
don't allow invalid syntax inside comment tag #1770
Conversation
54996ab
to
8b4bb21
Compare
8b4bb21
to
3c5ad7d
Compare
assert_raises(Liquid::SyntaxError) do | ||
assert_template_result("", <<~LIQUID.chomp) | ||
{% comment %} | ||
{% assign foo = "1" | ||
{% endcomment %} | ||
LIQUID | ||
end | ||
|
||
assert_raises(Liquid::SyntaxError) do | ||
assert_template_result("", <<~LIQUID.chomp) | ||
{% comment %} | ||
{% comment %} | ||
{% invalid | ||
{% endcomment %} | ||
{% endcomment %} | ||
LIQUID | ||
end | ||
|
||
assert_raises(Liquid::SyntaxError) do | ||
assert_template_result("", <<~LIQUID.chomp) | ||
{% comment %} | ||
{% {{ {%- endcomment %} | ||
LIQUID | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these should be valid templates right? Incomplete tags should be allowed inside of a comment block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, however, we can't introduce a change that will break existing Liquid templates.
For an example,
{% comment %}
{% assign a = 123
{% endcomment %}
{% endcomment %}
This Liquid template is a valid with version 5.4.0
because the assign
tag is captured as {% assign a = 123 {% endcomment %}
. (Liquid allows extra string inside a tag)
So, if we parse comment
tag like the raw
tag, we would capture, we would ignore the {% assign a = 123
and capture {% endcomment %}
from line 3 as the comment tag's delimiter. Since the template has an extra {% endcomment %}
tag delimiter, the template is no longer valid.
What are you trying to solve?
#1755 introduced a new feature that allows invalid code to be inside a
comment
tag.For Liquid version
5.4.0
, this is a valid template, and not with our currentmain
branch:The
assign
tag is not closed immediately,{% assign a = 1 {% endcomment %}
is parsed as theassign
tag.Since the #1755 changed the
comment
tag parser to use theBlockBody::FullTokenPossiblyInvalid
regex pattern, it parses{% assign a = 1 {% endcomment %}
to be thecomment
tag delimiter, and it raises a syntax error by the extra{% endcomment %}
token.How are you solving this issue?
In order to remove this breaking change, this PR updates the
comment
to parse tokens likeBlockBody
and not likeraw
tag.However, the
comment
tag will still allow unclosed tags such as this example: