diff --git a/lib/liquid/block_body.rb b/lib/liquid/block_body.rb index e4ada7d16..a6150900b 100644 --- a/lib/liquid/block_body.rb +++ b/lib/liquid/block_body.rb @@ -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 @@ -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) diff --git a/test/unit/tags/comment_tag_unit_test.rb b/test/unit/tags/comment_tag_unit_test.rb index 56618b720..ad2a0d187 100644 --- a/test/unit/tags/comment_tag_unit_test.rb +++ b/test/unit/tags/comment_tag_unit_test.rb @@ -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