Compare commits

..

No commits in common. "e180535784b0375340dfc3fd7696d117f9f2a2ec" and "dbf0aa8cd58593ebc6942d47df42cfbc80f060d1" have entirely different histories.

4 changed files with 22 additions and 33 deletions

View File

@ -6,7 +6,6 @@ module Liquid
class BlockBody
LiquidTagToken = /\A\s*(#{TagName})\s*(.*?)\z/o
FullToken = /\A#{TagStart}#{WhitespaceControl}?(\s*)(#{TagName})(\s*)(.*?)#{WhitespaceControl}?#{TagEnd}\z/om
FullTokenPossiblyInvalid = /\A(.*)#{TagStart}#{WhitespaceControl}?\s*(\w+)\s*(.*)?#{WhitespaceControl}?#{TagEnd}\z/om
ContentOfVariable = /\A#{VariableStart}#{WhitespaceControl}?(.*?)#{WhitespaceControl}?#{VariableEnd}\z/om
WhitespaceOrNothing = /\A\s*\z/
TAGSTART = "{%"

View File

@ -41,18 +41,22 @@ module Liquid
# 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)
tag_name_match = BlockBody::FullToken.match(token)
next if tag_name_match.nil?
tag_name = tag_name_match[2]
case tag_name
when "raw"
if tag_name == "raw"
# raw tags are required to be closed
parse_raw_tag_body(tokens)
when "comment"
next
end
if tag_name_match[2] == "comment"
comment_tag_depth += 1
when "endcomment"
next
elsif tag_name_match[2] == "endcomment"
comment_tag_depth -= 1
return false if comment_tag_depth.zero?
@ -69,7 +73,7 @@ module Liquid
def parse_raw_tag_body(tokens)
while (token = tokens.send(:shift))
return if token =~ BlockBody::FullTokenPossiblyInvalid && "endraw" == Regexp.last_match(2)
return if token =~ Raw::FullTokenPossiblyInvalid && "endraw" == Regexp.last_match(2)
end
raise_tag_never_closed("raw")

View File

@ -14,6 +14,7 @@ module Liquid
# @liquid_syntax_keyword expression The expression to be output without being rendered.
class Raw < Block
Syntax = /\A\s*\z/
FullTokenPossiblyInvalid = /\A(.*)#{TagStart}#{WhitespaceControl}?\s*(\w+)\s*(.*)?#{WhitespaceControl}?#{TagEnd}\z/om
def initialize(tag_name, markup, parse_context)
super
@ -24,7 +25,7 @@ module Liquid
def parse(tokens)
@body = +''
while (token = tokens.shift)
if token =~ BlockBody::FullTokenPossiblyInvalid && block_delimiter == Regexp.last_match(2)
if token =~ FullTokenPossiblyInvalid && block_delimiter == Regexp.last_match(2)
parse_context.trim_whitespace = (token[-3] == WhitespaceControl)
@body << Regexp.last_match(1) if Regexp.last_match(1) != ""
return

View File

@ -4,7 +4,7 @@ require 'test_helper'
class CommentTagUnitTest < Minitest::Test
def test_does_not_parse_nodes_inside_a_comment
assert_template_result("", <<~LIQUID.chomp)
template = Liquid::Template.parse(<<~LIQUID.chomp, line_numbers: true)
{% comment %}
{% if true %}
{% if ... %}
@ -16,31 +16,12 @@ class CommentTagUnitTest < Minitest::Test
{% endcase %}
{% endcomment %}
LIQUID
end
def test_allows_incomplete_tags_inside_a_comment
assert_template_result("", <<~LIQUID.chomp)
{% comment %}
{% assign foo = "1"
{% endcomment %}
LIQUID
assert_template_result("", <<~LIQUID.chomp)
{% comment %}
{% comment %}
{% invalid
{% endcomment %}
{% endcomment %}
LIQUID
assert_template_result("", <<~LIQUID.chomp)
{% comment %}
{% {{ {%- endcomment %}
LIQUID
assert_equal("", template.render)
end
def test_child_comment_tags_need_to_be_closed
assert_template_result("", <<~LIQUID.chomp)
template = Liquid::Template.parse(<<~LIQUID.chomp, line_numbers: true)
{% comment %}
{% comment %}
{% comment %}{% endcomment %}
@ -48,8 +29,10 @@ class CommentTagUnitTest < Minitest::Test
{% endcomment %}
LIQUID
assert_equal("", template.render)
assert_raises(Liquid::SyntaxError) do
assert_template_result("", <<~LIQUID.chomp)
Liquid::Template.parse(<<~LIQUID.chomp, line_numbers: true)
{% comment %}
{% comment %}
{% comment %}
@ -60,7 +43,7 @@ class CommentTagUnitTest < Minitest::Test
end
def test_child_raw_tags_need_to_be_closed
assert_template_result("", <<~LIQUID.chomp)
template = Liquid::Template.parse(<<~LIQUID.chomp, line_numbers: true)
{% comment %}
{% raw %}
{% endcomment %}
@ -68,8 +51,10 @@ class CommentTagUnitTest < Minitest::Test
{% endcomment %}
LIQUID
assert_equal("", template.render)
assert_raises(Liquid::SyntaxError) do
Liquid::Template.parse(<<~LIQUID.chomp)
Liquid::Template.parse(<<~LIQUID.chomp, line_numbers: true)
{% comment %}
{% raw %}
{% endcomment %}