mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-29 07:05:12 -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"
|
when "endcomment"
|
||||||
comment_tag_depth -= 1
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -155,4 +155,15 @@ class CommentTagUnitTest < Minitest::Test
|
|||||||
assert_template_result('', "{% comment %}123{% endcomment\nxyz %}")
|
assert_template_result('', "{% comment %}123{% endcomment\nxyz %}")
|
||||||
assert_template_result('', "{% comment %}123{% endcomment\n xyz endcomment %}")
|
assert_template_result('', "{% comment %}123{% endcomment\n xyz endcomment %}")
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user