From a3c837687e5e6d800aed7f4f6d29b25f7155c275 Mon Sep 17 00:00:00 2001 From: Michael Go Date: Fri, 5 Jan 2024 10:17:37 -0400 Subject: [PATCH] don't reset Liquid tag's whitespace control from comment tag --- lib/liquid/tags/comment.rb | 8 ++++---- test/unit/tags/comment_tag_unit_test.rb | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/liquid/tags/comment.rb b/lib/liquid/tags/comment.rb index 7b83c3ee6..798355d54 100644 --- a/lib/liquid/tags/comment.rb +++ b/lib/liquid/tags/comment.rb @@ -61,11 +61,11 @@ def parse_body(body, tokenizer) comment_tag_depth += 1 when "endcomment" comment_tag_depth -= 1 + end - if comment_tag_depth.zero? - parse_context.trim_whitespace = (token[-3] == WhitespaceControl) - return false - end + if comment_tag_depth.zero? + parse_context.trim_whitespace = (token[-3] == WhitespaceControl) unless tokenizer.for_liquid_tag + return false end end diff --git a/test/unit/tags/comment_tag_unit_test.rb b/test/unit/tags/comment_tag_unit_test.rb index b5bc48fa1..56618b720 100644 --- a/test/unit/tags/comment_tag_unit_test.rb +++ b/test/unit/tags/comment_tag_unit_test.rb @@ -187,4 +187,16 @@ def test_with_whitespace_control Hello! LIQUID end + + def test_dont_override_liquid_tag_whitespace_control + assert_template_result("Hello!World!", <<~LIQUID.chomp) + Hello! + {%- liquid + comment + this is inside a liquid tag + endcomment + -%} + World! + LIQUID + end end