Merge pull request #1770 from Shopify/revert-invalid-comment-body

don't allow invalid syntax inside comment tag
This commit is contained in:
Michael Go
2024-01-02 11:07:05 -04:00
committed by GitHub
2 changed files with 34 additions and 20 deletions
+2 -8
View File
@@ -49,15 +49,9 @@ module Liquid
next if tag_name_match.nil? next if tag_name_match.nil?
tag_name_match[1] tag_name_match[1]
elsif token =~ BlockBody::FullToken && Regexp.last_match(2) == "comment" || Regexp.last_match(2) == "endcomment"
# aggressively match comment tag or comment tag delimiter
Regexp.last_match(2)
else else
tag_name_match = BlockBody::FullTokenPossiblyInvalid.match(token) token =~ BlockBody::FullToken
Regexp.last_match(2)
next if tag_name_match.nil?
tag_name_match[2]
end end
case tag_name case tag_name
+32 -12
View File
@@ -31,25 +31,45 @@ class CommentTagUnitTest < Minitest::Test
LIQUID LIQUID
end end
def test_allows_incomplete_tags_inside_a_comment def test_allows_unclosed_tags
assert_template_result("", <<~LIQUID.chomp) assert_template_result('', <<~LIQUID.chomp)
{% comment %} {% comment %}
{% assign foo = "1" {% if true %}
{% endcomment %}
LIQUID
end
def test_open_tags_in_comment
assert_template_result('', <<~LIQUID.chomp)
{% comment %}
{% assign a = 123 {% comment %}
{% endcomment %} {% endcomment %}
LIQUID LIQUID
assert_template_result("", <<~LIQUID.chomp) assert_raises(Liquid::SyntaxError) do
{% comment %} assert_template_result("", <<~LIQUID.chomp)
{% comment %} {% comment %}
{% invalid {% assign foo = "1"
{% endcomment %} {% endcomment %}
{% endcomment %} LIQUID
LIQUID end
assert_template_result("", <<~LIQUID.chomp) assert_raises(Liquid::SyntaxError) do
{% comment %} assert_template_result("", <<~LIQUID.chomp)
{% {{ {%- endcomment %} {% comment %}
LIQUID {% comment %}
{% invalid
{% endcomment %}
{% endcomment %}
LIQUID
end
assert_raises(Liquid::SyntaxError) do
assert_template_result("", <<~LIQUID.chomp)
{% comment %}
{% {{ {%- endcomment %}
LIQUID
end
end end
def test_child_comment_tags_need_to_be_closed def test_child_comment_tags_need_to_be_closed