From 6dafc19b6d9186a2d0ee2f330f9f349567150ee8 Mon Sep 17 00:00:00 2001 From: Michael Go Date: Fri, 10 Nov 2023 15:42:54 -0400 Subject: [PATCH] fix parsing comment tag delimiter with extra strings --- lib/liquid/tags/comment.rb | 5 +++++ test/unit/tags/comment_tag_unit_test.rb | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/liquid/tags/comment.rb b/lib/liquid/tags/comment.rb index 060a0293..d6f85571 100644 --- a/lib/liquid/tags/comment.rb +++ b/lib/liquid/tags/comment.rb @@ -15,6 +15,8 @@ module Liquid # {% endcomment %} # @liquid_syntax_keyword content The content of the comment. class Comment < Block + TagDelimiter = /\A(.*)#{TagStart}#{WhitespaceControl}?\s*(endcomment)\s*(.*)?#{WhitespaceControl}?#{TagEnd}\z/om + def render_to_output_buffer(_context, output) output end @@ -49,6 +51,9 @@ module Liquid next if tag_name_match.nil? tag_name_match[1] + elsif TagDelimiter.match?(token) + # aggressively match comment delimiter first + "endcomment" else tag_name_match = BlockBody::FullTokenPossiblyInvalid.match(token) diff --git a/test/unit/tags/comment_tag_unit_test.rb b/test/unit/tags/comment_tag_unit_test.rb index 64f96f3a..11d2fd15 100644 --- a/test/unit/tags/comment_tag_unit_test.rb +++ b/test/unit/tags/comment_tag_unit_test.rb @@ -107,4 +107,18 @@ class CommentTagUnitTest < Minitest::Test assert_equal(expected, output) end + + def test_comment_tag_delimiter_with_extra_strings + assert_template_result( + '', + <<~LIQUID.chomp, + {% comment %} + {% comment %} + {% endcomment + {% if true %} + {% endif %} + {% endcomment %} + LIQUID + ) + end end