diff --git a/lib/liquid/tags/comment.rb b/lib/liquid/tags/comment.rb index 7b83c3ee..798355d5 100644 --- a/lib/liquid/tags/comment.rb +++ b/lib/liquid/tags/comment.rb @@ -61,11 +61,11 @@ module Liquid 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 b5bc48fa..56618b72 100644 --- a/test/unit/tags/comment_tag_unit_test.rb +++ b/test/unit/tags/comment_tag_unit_test.rb @@ -187,4 +187,16 @@ class CommentTagUnitTest < Minitest::Test 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