mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-16 09:20:42 -07:00
Merge pull request #1764 from Shopify/fix-comment-tag-whitespace-control
implement whitespace control to comment tag
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user