Merge pull request #1769 from Shopify/comment-tag-with-extra-string

fix parsing comment tag with extra string
This commit is contained in:
Michael Go
2023-12-13 14:16:44 -04:00
committed by GitHub
2 changed files with 4 additions and 8 deletions
+3 -8
View File
@@ -15,8 +15,6 @@ module Liquid
# {% endcomment %}
# @liquid_syntax_keyword content The content of the comment.
class Comment < Block
TAG_DELIMITER = /\A(.*)#{TagStart}#{WhitespaceControl}?\s*(endcomment)\s*(\s.*)?#{WhitespaceControl}?#{TagEnd}\z/om
def render_to_output_buffer(_context, output)
output
end
@@ -51,12 +49,9 @@ module Liquid
next if tag_name_match.nil?
tag_name_match[1]
elsif TAG_DELIMITER.match?(token)
# aggressively match comment delimiter
"endcomment"
elsif token =~ BlockBody::FullToken && Regexp.last_match(2) == "comment"
# aggressively match comment tag
"comment"
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
tag_name_match = BlockBody::FullTokenPossiblyInvalid.match(token)
+1
View File
@@ -154,6 +154,7 @@ class CommentTagUnitTest < Minitest::Test
assert_template_result('', "{% comment %}123{% endcomment\txyz %}")
assert_template_result('', "{% comment %}123{% endcomment\nxyz %}")
assert_template_result('', "{% comment %}123{% endcomment\n xyz endcomment %}")
assert_template_result('', "{%comment}{% assign a = 1 %}{%endcomment}{% endif %}")
end
def test_with_whitespace_control