Skip to content

Commit 6e3e26b

Browse files
committed
don't add comment node to the nodelist
1 parent fdd8c71 commit 6e3e26b

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

lib/liquid/block_body.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ def freeze
5858
return yield tag_name, markup
5959
end
6060
new_tag = tag.parse(tag_name, markup, tokenizer, parse_context)
61+
62+
next if new_tag.is_a?(Comment)
63+
6164
@blank &&= new_tag.blank?
6265
@nodelist << new_tag
6366
end
@@ -153,6 +156,9 @@ def self.rescue_render_node(context, output, line_number, exc, blank_tag)
153156
return yield tag_name, markup
154157
end
155158
new_tag = tag.parse(tag_name, markup, tokenizer, parse_context)
159+
160+
next if new_tag.is_a?(Comment)
161+
156162
@blank &&= new_tag.blank?
157163
@nodelist << new_tag
158164
when token.start_with?(VARSTART)

test/unit/block_unit_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def test_variable_many_embedded_fragments
4949

5050
def test_with_block
5151
template = Liquid::Template.parse(" {% comment %} {% endcomment %} ")
52-
assert_equal([String, Comment, String], block_types(template.root.nodelist))
53-
assert_equal(3, template.root.nodelist.size)
52+
assert_equal([String, String], block_types(template.root.nodelist))
53+
assert_equal(2, template.root.nodelist.size)
5454
end
5555

5656
private

test/unit/tags/comment_tag_unit_test.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,26 @@ def test_dont_override_liquid_tag_whitespace_control
199199
World!
200200
LIQUID
201201
end
202+
203+
def test_comment_tag_node_is_not_in_nodelist
204+
template = Liquid::Template.parse(<<~LIQUID.chomp)
205+
{% comment %}
206+
{% if true %}
207+
{% endif %}
208+
{% endcomment %}
209+
LIQUID
210+
211+
assert_equal(0, template.root.nodelist.size)
212+
213+
template = Liquid::Template.parse(<<~LIQUID.chomp)
214+
{% liquid
215+
comment
216+
if true
217+
endif
218+
endcomment
219+
%}
220+
LIQUID
221+
222+
assert_equal(0, template.root.nodelist.size)
223+
end
202224
end

test/unit/template_unit_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ class TemplateUnitTest < Minitest::Test
77

88
def test_sets_default_localization_in_document
99
t = Template.new
10-
t.parse('{%comment%}{%endcomment%}')
10+
t.parse('{%raw%}{%endraw%}')
1111
assert_instance_of(I18n, t.root.nodelist[0].options[:locale])
1212
end
1313

1414
def test_sets_default_localization_in_context_with_quick_initialization
1515
t = Template.new
16-
t.parse('{%comment%}{%endcomment%}', locale: I18n.new(fixture("en_locale.yml")))
16+
t.parse('{%raw%}{%endraw%}', locale: I18n.new(fixture("en_locale.yml")))
1717

1818
locale = t.root.nodelist[0].options[:locale]
1919
assert_instance_of(I18n, locale)

0 commit comments

Comments
 (0)