mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-15 08:50:45 -07:00
fix parsing nested comment tag with extra strings
This commit is contained in:
@@ -15,7 +15,7 @@ module Liquid
|
|||||||
# {% endcomment %}
|
# {% endcomment %}
|
||||||
# @liquid_syntax_keyword content The content of the comment.
|
# @liquid_syntax_keyword content The content of the comment.
|
||||||
class Comment < Block
|
class Comment < Block
|
||||||
TagDelimiter = /\A(.*)#{TagStart}#{WhitespaceControl}?\s*(endcomment)\s*(.*)?#{WhitespaceControl}?#{TagEnd}\z/om
|
TAG_DELIMITER = /\A(.*)#{TagStart}#{WhitespaceControl}?\s*(endcomment)\s*(.*)?#{WhitespaceControl}?#{TagEnd}\z/om
|
||||||
|
|
||||||
def render_to_output_buffer(_context, output)
|
def render_to_output_buffer(_context, output)
|
||||||
output
|
output
|
||||||
@@ -51,9 +51,12 @@ module Liquid
|
|||||||
next if tag_name_match.nil?
|
next if tag_name_match.nil?
|
||||||
|
|
||||||
tag_name_match[1]
|
tag_name_match[1]
|
||||||
elsif TagDelimiter.match?(token)
|
elsif TAG_DELIMITER.match?(token)
|
||||||
# aggressively match comment delimiter first
|
# aggressively match comment delimiter
|
||||||
"endcomment"
|
"endcomment"
|
||||||
|
elsif token =~ BlockBody::FullToken && Regexp.last_match(2) == "comment"
|
||||||
|
# aggressively match comment tag
|
||||||
|
"comment"
|
||||||
else
|
else
|
||||||
tag_name_match = BlockBody::FullTokenPossiblyInvalid.match(token)
|
tag_name_match = BlockBody::FullTokenPossiblyInvalid.match(token)
|
||||||
|
|
||||||
|
|||||||
@@ -121,4 +121,18 @@ class CommentTagUnitTest < Minitest::Test
|
|||||||
LIQUID
|
LIQUID
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_nested_comment_tag_with_extra_strings
|
||||||
|
assert_template_result(
|
||||||
|
'',
|
||||||
|
<<~LIQUID.chomp,
|
||||||
|
{% comment %}
|
||||||
|
{% comment
|
||||||
|
{% assign foo = 1 %}
|
||||||
|
{% endcomment
|
||||||
|
{% assign foo = 1 %}
|
||||||
|
{% endcomment %}
|
||||||
|
LIQUID
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user