Merge pull request #1764 from Shopify/fix-comment-tag-whitespace-control

implement whitespace control to comment tag
This commit is contained in:
Michael Go
2023-12-06 14:30:16 -05:00
committed by GitHub
2 changed files with 15 additions and 1 deletions
+4 -1
View File
@@ -73,7 +73,10 @@ module Liquid
when "endcomment"
comment_tag_depth -= 1
return false if comment_tag_depth.zero?
if comment_tag_depth.zero?
parse_context.trim_whitespace = (token[-3] == WhitespaceControl)
return false
end
end
end
+11
View File
@@ -155,4 +155,15 @@ class CommentTagUnitTest < Minitest::Test
assert_template_result('', "{% comment %}123{% endcomment\nxyz %}")
assert_template_result('', "{% comment %}123{% endcomment\n xyz endcomment %}")
end
def test_with_whitespace_control
assert_template_result("Hello!", " {%- comment -%}123{%- endcomment -%}Hello!")
assert_template_result("Hello!", "{%- comment -%}123{%- endcomment -%} Hello!")
assert_template_result("Hello!", " {%- comment -%}123{%- endcomment -%} Hello!")
assert_template_result("Hello!", <<~LIQUID.chomp)
{%- comment %}Whitespace control!{% endcomment -%}
Hello!
LIQUID
end
end