Compare commits

...
Author SHA1 Message Date
Christophe Naud-Dulude 02b6be4025 Potential fix 2021-11-30 14:10:34 -05:00
Christophe Naud-Dulude f3638b3eb4 Test parsing of Liquid code in comments 2021-11-30 11:56:49 -05:00
3 changed files with 42 additions and 0 deletions
+13
View File
@@ -2,6 +2,19 @@
module Liquid
class Comment < Block
# Potential fix
FullTokenPossiblyInvalid = /\A(.*)#{TagStart}#{WhitespaceControl}?\s*(\w+)\s*(.*)?#{WhitespaceControl}?#{TagEnd}\z/om
def parse(tokens)
while (token = tokens.shift)
if token =~ FullTokenPossiblyInvalid && block_delimiter == Regexp.last_match(2)
return
end
end
raise_tag_never_closed(block_name)
end
def render_to_output_buffer(_context, output)
output
end
+4
View File
@@ -15,15 +15,19 @@ module Liquid
attr_reader :variable
def initialize(tag_name, markup, parse_context)
puts "Initializing Echo tag"
super
@variable = Variable.new(markup, parse_context)
end
def render(context)
puts "Render Echo tag"
@variable.render_to_output_buffer(context, +'')
end
class ParseTreeVisitor < Liquid::ParseTreeVisitor
puts "ParseTreeVisitor Echo tag"
def children
[@node.variable]
end
+25
View File
@@ -0,0 +1,25 @@
# frozen_string_literal: true
require 'test_helper'
class CommentTagTest < Minitest::Test
include Liquid
def test_single_line_comments_parse
assert_template_result('Before comment', <<~LIQUID)
Before comment
{%- comment -%}
Regular text comment
Liquid in comment: {% echo 'Hi from comment' %}
{%- endcomment -%}
LIQUID
end
def test_multi_line_comments_parse
assert_template_result('Before comment', <<~LIQUID)
Before comment
{%- comment -%} Regular text comment {%- endcomment -%}
{%- comment -%} Liquid in comment: {% echo 'Hi from comment' %} {%- endcomment -%}
LIQUID
end
end # CommentTagTest