mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-19 19:00:39 -07:00
Fix broken 'raw' tag parsing (issue #204)
This commit is contained in:
@@ -1,12 +1,14 @@
|
|||||||
module Liquid
|
module Liquid
|
||||||
class Raw < Block
|
class Raw < Block
|
||||||
|
FullTokenPossiblyInvalid = /^(.*)#{TagStart}\s*(\w+)\s*(.*)?#{TagEnd}$/o
|
||||||
|
|
||||||
def parse(tokens)
|
def parse(tokens)
|
||||||
@nodelist ||= []
|
@nodelist ||= []
|
||||||
@nodelist.clear
|
@nodelist.clear
|
||||||
|
|
||||||
while token = tokens.shift
|
while token = tokens.shift
|
||||||
if token =~ FullToken
|
if token =~ FullTokenPossiblyInvalid
|
||||||
if block_delimiter == $1
|
@nodelist << $1 if $1 != ""
|
||||||
|
if block_delimiter == $2
|
||||||
end_tag
|
end_tag
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -18,4 +20,3 @@ module Liquid
|
|||||||
|
|
||||||
Template.register_tag('raw', Raw)
|
Template.register_tag('raw', Raw)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,16 @@ class RawTagTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_output_in_raw
|
def test_output_in_raw
|
||||||
assert_template_result '{{ test }}',
|
assert_template_result '{{ test }}', '{% raw %}{{ test }}{% endraw %}'
|
||||||
'{% 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
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user