mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 00:55:11 -07:00
fix parsing comment block body inside a liquid tag
This commit is contained in:
@@ -28,7 +28,7 @@ module Liquid
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def parse_body(body, tokens)
|
def parse_body(body, tokenizer)
|
||||||
if parse_context.depth >= MAX_DEPTH
|
if parse_context.depth >= MAX_DEPTH
|
||||||
raise StackLevelError, "Nesting too deep"
|
raise StackLevelError, "Nesting too deep"
|
||||||
end
|
end
|
||||||
@@ -40,16 +40,26 @@ module Liquid
|
|||||||
# Consume tokens without creating child nodes.
|
# Consume tokens without creating child nodes.
|
||||||
# The children tag doesn't require to be a valid Liquid except the comment and raw tag.
|
# The children tag doesn't require to be a valid Liquid except the comment and raw tag.
|
||||||
# The child comment and raw tag must be closed.
|
# The child comment and raw tag must be closed.
|
||||||
while (token = tokens.send(:shift))
|
while (token = tokenizer.send(:shift))
|
||||||
|
tag_name = if tokenizer.for_liquid_tag
|
||||||
|
next if token.empty? || token.match?(BlockBody::WhitespaceOrNothing)
|
||||||
|
|
||||||
|
tag_name_match = BlockBody::LiquidTagToken.match(token)
|
||||||
|
|
||||||
|
next if tag_name_match.nil?
|
||||||
|
|
||||||
|
tag_name_match[1]
|
||||||
|
else
|
||||||
tag_name_match = BlockBody::FullTokenPossiblyInvalid.match(token)
|
tag_name_match = BlockBody::FullTokenPossiblyInvalid.match(token)
|
||||||
|
|
||||||
next if tag_name_match.nil?
|
next if tag_name_match.nil?
|
||||||
|
|
||||||
tag_name = tag_name_match[2]
|
tag_name_match[2]
|
||||||
|
end
|
||||||
|
|
||||||
case tag_name
|
case tag_name
|
||||||
when "raw"
|
when "raw"
|
||||||
parse_raw_tag_body(tokens)
|
parse_raw_tag_body(tokenizer)
|
||||||
when "comment"
|
when "comment"
|
||||||
comment_tag_depth += 1
|
comment_tag_depth += 1
|
||||||
when "endcomment"
|
when "endcomment"
|
||||||
@@ -67,8 +77,8 @@ module Liquid
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_raw_tag_body(tokens)
|
def parse_raw_tag_body(tokenizer)
|
||||||
while (token = tokens.send(:shift))
|
while (token = tokenizer.send(:shift))
|
||||||
return if token =~ BlockBody::FullTokenPossiblyInvalid && "endraw" == Regexp.last_match(2)
|
return if token =~ BlockBody::FullTokenPossiblyInvalid && "endraw" == Regexp.last_match(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,19 @@
|
|||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class CommentTagUnitTest < Minitest::Test
|
class CommentTagUnitTest < Minitest::Test
|
||||||
|
def test_comment_inside_liquid_tag
|
||||||
|
assert_template_result("", <<~LIQUID.chomp)
|
||||||
|
{% liquid
|
||||||
|
if 1 != 1
|
||||||
|
comment
|
||||||
|
else
|
||||||
|
echo 123
|
||||||
|
endcomment
|
||||||
|
endif
|
||||||
|
%}
|
||||||
|
LIQUID
|
||||||
|
end
|
||||||
|
|
||||||
def test_does_not_parse_nodes_inside_a_comment
|
def test_does_not_parse_nodes_inside_a_comment
|
||||||
assert_template_result("", <<~LIQUID.chomp)
|
assert_template_result("", <<~LIQUID.chomp)
|
||||||
{% comment %}
|
{% comment %}
|
||||||
|
|||||||
Reference in New Issue
Block a user