Fix broken 'raw' tag parsing (issue #204)

This commit is contained in:
Florian Weingarten 2013-06-14 11:10:26 -04:00
parent 81f6c79c53
commit e47d1af03a
2 changed files with 16 additions and 6 deletions

View File

@ -1,12 +1,14 @@
module Liquid
class Raw < Block
FullTokenPossiblyInvalid = /^(.*)#{TagStart}\s*(\w+)\s*(.*)?#{TagEnd}$/o
def parse(tokens)
@nodelist ||= []
@nodelist.clear
while token = tokens.shift
if token =~ FullToken
if block_delimiter == $1
if token =~ FullTokenPossiblyInvalid
@nodelist << $1 if $1 != ""
if block_delimiter == $2
end_tag
return
end
@ -18,4 +20,3 @@ module Liquid
Template.register_tag('raw', Raw)
end

View File

@ -9,7 +9,16 @@ class RawTagTest < Test::Unit::TestCase
end
def test_output_in_raw
assert_template_result '{{ test }}',
'{% raw %}{{ test }}{% endraw %}'
assert_template_result '{{ test }}', '{% raw %}{{ test }}{% endraw %}'
end
def test_open_tag_in_raw
assert_template_result ' Foobar {% invalid ', '{% raw %} Foobar {% invalid {% endraw %}'
assert_template_result ' Foobar invalid %} ', '{% raw %} Foobar invalid %} {% endraw %}'
assert_template_result ' Foobar {{ invalid ', '{% raw %} Foobar {{ invalid {% endraw %}'
assert_template_result ' Foobar invalid }} ', '{% raw %} Foobar invalid }} {% endraw %}'
assert_template_result ' Foobar {% invalid {% {% endraw ', '{% raw %} Foobar {% invalid {% {% endraw {% endraw %}'
assert_template_result ' Foobar {% {% {% ', '{% raw %} Foobar {% {% {% {% endraw %}'
assert_template_result ' test {% raw %} {% endraw %}', '{% raw %} test {% raw %} {% {% endraw %}endraw %}'
end
end