mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-16 01:10:41 -07:00
fix parsing comment block body inside a liquid tag
This commit is contained in:
@@ -28,7 +28,7 @@ module Liquid
|
||||
|
||||
private
|
||||
|
||||
def parse_body(body, tokens)
|
||||
def parse_body(body, tokenizer)
|
||||
if parse_context.depth >= MAX_DEPTH
|
||||
raise StackLevelError, "Nesting too deep"
|
||||
end
|
||||
@@ -40,16 +40,26 @@ module Liquid
|
||||
# Consume tokens without creating child nodes.
|
||||
# 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.
|
||||
while (token = tokens.send(:shift))
|
||||
tag_name_match = BlockBody::FullTokenPossiblyInvalid.match(token)
|
||||
while (token = tokenizer.send(:shift))
|
||||
tag_name = if tokenizer.for_liquid_tag
|
||||
next if token.empty? || token.match?(BlockBody::WhitespaceOrNothing)
|
||||
|
||||
next if tag_name_match.nil?
|
||||
tag_name_match = BlockBody::LiquidTagToken.match(token)
|
||||
|
||||
tag_name = tag_name_match[2]
|
||||
next if tag_name_match.nil?
|
||||
|
||||
tag_name_match[1]
|
||||
else
|
||||
tag_name_match = BlockBody::FullTokenPossiblyInvalid.match(token)
|
||||
|
||||
next if tag_name_match.nil?
|
||||
|
||||
tag_name_match[2]
|
||||
end
|
||||
|
||||
case tag_name
|
||||
when "raw"
|
||||
parse_raw_tag_body(tokens)
|
||||
parse_raw_tag_body(tokenizer)
|
||||
when "comment"
|
||||
comment_tag_depth += 1
|
||||
when "endcomment"
|
||||
@@ -67,8 +77,8 @@ module Liquid
|
||||
false
|
||||
end
|
||||
|
||||
def parse_raw_tag_body(tokens)
|
||||
while (token = tokens.send(:shift))
|
||||
def parse_raw_tag_body(tokenizer)
|
||||
while (token = tokenizer.send(:shift))
|
||||
return if token =~ BlockBody::FullTokenPossiblyInvalid && "endraw" == Regexp.last_match(2)
|
||||
end
|
||||
|
||||
|
||||
@@ -3,6 +3,19 @@
|
||||
require 'test_helper'
|
||||
|
||||
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
|
||||
assert_template_result("", <<~LIQUID.chomp)
|
||||
{% comment %}
|
||||
|
||||
Reference in New Issue
Block a user