Ensure raw tag has no arguments

This commit is contained in:
Justin Li 2015-06-02 14:32:39 -04:00
parent 86d8b552da
commit 719a98a25e
3 changed files with 12 additions and 1 deletions

View File

@ -1,6 +1,7 @@
---
errors:
syntax:
tag_unexpected_args: "Syntax Error in '%{tag}' - Valid syntax: %{tag}"
assign: "Syntax Error in 'assign' - Valid syntax: assign [var] = [source]"
capture: "Syntax Error in 'capture' - Valid syntax: capture [var]"
case: "Syntax Error in 'case' - Valid syntax: case [condition]"

View File

@ -1,7 +1,16 @@
module Liquid
class Raw < Block
Syntax = /\A\s*\z/om
FullTokenPossiblyInvalid = /\A(.*)#{TagStart}\s*(\w+)\s*(.*)?#{TagEnd}\z/om
def initialize(tag_name, markup, options)
super
unless markup =~ Syntax
raise SyntaxError.new(@options[:locale].t("errors.syntax.tag_unexpected_args".freeze, tag: tag_name))
end
end
def parse(tokens)
@body = ''
while token = tokens.shift

View File

@ -24,6 +24,7 @@ class RawTagTest < Minitest::Test
end
def test_invalid_raw
assert_match_syntax_error /tag was never closed/, '{% raw } foo {% endraw %}'
assert_match_syntax_error /tag was never closed/, '{% raw %} foo'
assert_match_syntax_error /Valid syntax/, '{% raw } foo %}{% endraw %}'
end
end