Skip to content

Commit

Permalink
don't add comment node to the nodelist
Browse files Browse the repository at this point in the history
  • Loading branch information
ggmichaelgo committed Dec 13, 2024
1 parent fdd8c71 commit e862c27
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/liquid/block_body.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def freeze
return yield tag_name, markup
end
new_tag = tag.parse(tag_name, markup, tokenizer, parse_context)

next if new_tag.is_a?(Comment)

@blank &&= new_tag.blank?
@nodelist << new_tag
end
Expand Down Expand Up @@ -153,6 +156,9 @@ def self.rescue_render_node(context, output, line_number, exc, blank_tag)
return yield tag_name, markup
end
new_tag = tag.parse(tag_name, markup, tokenizer, parse_context)

next if new_tag.is_a?(Comment)

@blank &&= new_tag.blank?
@nodelist << new_tag
when token.start_with?(VARSTART)
Expand Down
22 changes: 22 additions & 0 deletions test/unit/tags/comment_tag_unit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,26 @@ def test_dont_override_liquid_tag_whitespace_control
World!
LIQUID
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

0 comments on commit e862c27

Please sign in to comment.