From e180535784b0375340dfc3fd7696d117f9f2a2ec Mon Sep 17 00:00:00 2001 From: Michael Go Date: Wed, 8 Nov 2023 16:47:24 -0400 Subject: [PATCH] allow incomplete tags inside a comment tag --- lib/liquid/block_body.rb | 1 + lib/liquid/tags/comment.rb | 4 ++-- lib/liquid/tags/raw.rb | 3 +-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/liquid/block_body.rb b/lib/liquid/block_body.rb index 33a6a99f..61096de8 100644 --- a/lib/liquid/block_body.rb +++ b/lib/liquid/block_body.rb @@ -6,6 +6,7 @@ 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 = "{%" diff --git a/lib/liquid/tags/comment.rb b/lib/liquid/tags/comment.rb index 5c7315e0..df7b294c 100644 --- a/lib/liquid/tags/comment.rb +++ b/lib/liquid/tags/comment.rb @@ -41,7 +41,7 @@ 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::FullToken.match(token) + tag_name_match = BlockBody::FullTokenPossiblyInvalid.match(token) next if tag_name_match.nil? @@ -69,7 +69,7 @@ module Liquid def parse_raw_tag_body(tokens) while (token = tokens.send(:shift)) - return if token =~ Raw::FullTokenPossiblyInvalid && "endraw" == Regexp.last_match(2) + return if token =~ BlockBody::FullTokenPossiblyInvalid && "endraw" == Regexp.last_match(2) end raise_tag_never_closed("raw") diff --git a/lib/liquid/tags/raw.rb b/lib/liquid/tags/raw.rb index 7f3dec9b..02ee2b3c 100644 --- a/lib/liquid/tags/raw.rb +++ b/lib/liquid/tags/raw.rb @@ -14,7 +14,6 @@ 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 @@ -25,7 +24,7 @@ module Liquid def parse(tokens) @body = +'' while (token = tokens.shift) - if token =~ FullTokenPossiblyInvalid && block_delimiter == Regexp.last_match(2) + if token =~ BlockBody::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