From abed47547c306f35e7aada463e88d60919294efa Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Tue, 1 Nov 2022 13:04:41 -0400 Subject: [PATCH] Fix tags in comment --- lib/liquid/block_body.rb | 12 ++++++++++-- test/integration/tags/standard_tag_test.rb | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/liquid/block_body.rb b/lib/liquid/block_body.rb index a0d35a79..4674c5f3 100644 --- a/lib/liquid/block_body.rb +++ b/lib/liquid/block_body.rb @@ -109,14 +109,22 @@ module Liquid end end - private def parse_for_document(tokenizer, parse_context) + private def handle_invalid_tag_token(token, parse_context) + if token.end_with?('%}') + yield token, token + else + BlockBody.raise_missing_tag_terminator(token, parse_context) + end + end + + private def parse_for_document(tokenizer, parse_context, &block) while (token = tokenizer.shift) next if token.empty? case when token.start_with?(TAGSTART) whitespace_handler(token, parse_context) unless token =~ FullToken - BlockBody.raise_missing_tag_terminator(token, parse_context) + return handle_invalid_tag_token(token, parse_context, &block) end tag_name = Regexp.last_match(2) markup = Regexp.last_match(4) diff --git a/test/integration/tags/standard_tag_test.rb b/test/integration/tags/standard_tag_test.rb index 496a7c46..5ff425a4 100644 --- a/test/integration/tags/standard_tag_test.rb +++ b/test/integration/tags/standard_tag_test.rb @@ -36,6 +36,8 @@ class StandardTagTest < Minitest::Test assert_template_result('', '{%comment%}{% endif %}{%endcomment%}') assert_template_result('', '{% comment %}{% endwhatever %}{% endcomment %}') assert_template_result('', '{% comment %}{% raw %} {{%%%%}} }} { {% endcomment %} {% comment {% endraw %} {% endcomment %}') + assert_template_result('', '{% comment %}{% " %}{% endcomment %}') + assert_template_result('', '{% comment %}{%%}{% endcomment %}') assert_template_result('foobar', 'foo{%comment%}comment{%endcomment%}bar') assert_template_result('foobar', 'foo{% comment %}comment{% endcomment %}bar')