mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 09:05:13 -07:00
don't add comment node to the nodelist
This commit is contained in:
@@ -58,6 +58,9 @@ module Liquid
|
|||||||
return yield tag_name, markup
|
return yield tag_name, markup
|
||||||
end
|
end
|
||||||
new_tag = tag.parse(tag_name, markup, tokenizer, parse_context)
|
new_tag = tag.parse(tag_name, markup, tokenizer, parse_context)
|
||||||
|
|
||||||
|
next if new_tag.is_a?(Comment)
|
||||||
|
|
||||||
@blank &&= new_tag.blank?
|
@blank &&= new_tag.blank?
|
||||||
@nodelist << new_tag
|
@nodelist << new_tag
|
||||||
end
|
end
|
||||||
@@ -153,6 +156,9 @@ module Liquid
|
|||||||
return yield tag_name, markup
|
return yield tag_name, markup
|
||||||
end
|
end
|
||||||
new_tag = tag.parse(tag_name, markup, tokenizer, parse_context)
|
new_tag = tag.parse(tag_name, markup, tokenizer, parse_context)
|
||||||
|
|
||||||
|
next if new_tag.is_a?(Comment)
|
||||||
|
|
||||||
@blank &&= new_tag.blank?
|
@blank &&= new_tag.blank?
|
||||||
@nodelist << new_tag
|
@nodelist << new_tag
|
||||||
when token.start_with?(VARSTART)
|
when token.start_with?(VARSTART)
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ class BlockUnitTest < Minitest::Test
|
|||||||
|
|
||||||
def test_with_block
|
def test_with_block
|
||||||
template = Liquid::Template.parse(" {% comment %} {% endcomment %} ")
|
template = Liquid::Template.parse(" {% comment %} {% endcomment %} ")
|
||||||
assert_equal([String, Comment, String], block_types(template.root.nodelist))
|
assert_equal([String, String], block_types(template.root.nodelist))
|
||||||
assert_equal(3, template.root.nodelist.size)
|
assert_equal(2, template.root.nodelist.size)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -199,4 +199,26 @@ class CommentTagUnitTest < Minitest::Test
|
|||||||
World!
|
World!
|
||||||
LIQUID
|
LIQUID
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_comment_tag_node_is_not_in_nodelist
|
||||||
|
template = Liquid::Template.parse(<<~LIQUID.chomp)
|
||||||
|
{% comment %}
|
||||||
|
{% if true %}
|
||||||
|
{% endif %}
|
||||||
|
{% endcomment %}
|
||||||
|
LIQUID
|
||||||
|
|
||||||
|
assert_equal(0, template.root.nodelist.size)
|
||||||
|
|
||||||
|
template = Liquid::Template.parse(<<~LIQUID.chomp)
|
||||||
|
{% liquid
|
||||||
|
comment
|
||||||
|
if true
|
||||||
|
endif
|
||||||
|
endcomment
|
||||||
|
%}
|
||||||
|
LIQUID
|
||||||
|
|
||||||
|
assert_equal(0, template.root.nodelist.size)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,13 +7,13 @@ class TemplateUnitTest < Minitest::Test
|
|||||||
|
|
||||||
def test_sets_default_localization_in_document
|
def test_sets_default_localization_in_document
|
||||||
t = Template.new
|
t = Template.new
|
||||||
t.parse('{%comment%}{%endcomment%}')
|
t.parse('{%raw%}{%endraw%}')
|
||||||
assert_instance_of(I18n, t.root.nodelist[0].options[:locale])
|
assert_instance_of(I18n, t.root.nodelist[0].options[:locale])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_sets_default_localization_in_context_with_quick_initialization
|
def test_sets_default_localization_in_context_with_quick_initialization
|
||||||
t = Template.new
|
t = Template.new
|
||||||
t.parse('{%comment%}{%endcomment%}', locale: I18n.new(fixture("en_locale.yml")))
|
t.parse('{%raw%}{%endraw%}', locale: I18n.new(fixture("en_locale.yml")))
|
||||||
|
|
||||||
locale = t.root.nodelist[0].options[:locale]
|
locale = t.root.nodelist[0].options[:locale]
|
||||||
assert_instance_of(I18n, locale)
|
assert_instance_of(I18n, locale)
|
||||||
|
|||||||
Reference in New Issue
Block a user