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