rejects variables like a/b in for loops, closes #150

This commit is contained in:
Peter Schröder
2013-06-11 17:22:33 -04:00
parent 94ff457744
commit a2df5a421d
2 changed files with 32 additions and 26 deletions
+2 -2
View File
@@ -44,7 +44,7 @@ module Liquid
# forloop.last:: Returns true if the item is the last item. # forloop.last:: Returns true if the item is the last item.
# #
class For < Block class For < Block
Syntax = /(\w+)\s+in\s+(#{QuotedFragment}+)\s*(reversed)?/o Syntax = /\A(\w+)\s+in\s+(#{QuotedFragment}+)\s*(reversed)?/o
def initialize(tag_name, markup, tokens) def initialize(tag_name, markup, tokens)
if markup =~ Syntax if markup =~ Syntax
@@ -112,7 +112,7 @@ module Liquid
'rindex' => length - index, 'rindex' => length - index,
'rindex0' => length - index - 1, 'rindex0' => length - index - 1,
'first' => (index == 0), 'first' => (index == 0),
'last' => (index == length - 1) } 'last' => (index == length - 1) }
result << render_all(@for_block, context) result << render_all(@for_block, context)
+6
View File
@@ -281,4 +281,10 @@ HERE
def test_blank_string_not_iterable def test_blank_string_not_iterable
assert_template_result('', "{% for char in characters %}I WILL NOT BE OUTPUT{% endfor %}", 'characters' => '') assert_template_result('', "{% for char in characters %}I WILL NOT BE OUTPUT{% endfor %}", 'characters' => '')
end end
def test_bad_variable_naming_in_for_loop
assert_raise(Liquid::SyntaxError) do
Liquid::Template.parse('{% for a/b in x %}{% endfor %}')
end
end
end end