mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Fail with trailing elements in the cycle tag
This commit is contained in:
committed by
Guilherme Carreiro
parent
327790cdce
commit
e2a15334f0
@@ -74,6 +74,8 @@ module Liquid
|
|||||||
break unless p.consume?(:comma)
|
break unless p.consume?(:comma)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
p.consume(:end_of_string)
|
||||||
|
|
||||||
unless @is_named
|
unless @is_named
|
||||||
@name = @variables.to_s
|
@name = @variables.to_s
|
||||||
@is_named = !@name.match?(/\w+:0x\h{8}/)
|
@is_named = !@name.match?(/\w+:0x\h{8}/)
|
||||||
|
|||||||
@@ -76,4 +76,40 @@ class CycleTagTest < Minitest::Test
|
|||||||
assert_match(expected_error, error2.message)
|
assert_match(expected_error, error2.message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_cycle_with_trailing_elements
|
||||||
|
assignments = "{% assign a = 'A' %}{% assign n = 'N' %}"
|
||||||
|
|
||||||
|
template1 = "#{assignments}{% cycle 'a' 'b', 'c' %}"
|
||||||
|
template2 = "#{assignments}{% cycle name: 'a' 'b', 'c' %}"
|
||||||
|
template3 = "#{assignments}{% cycle name: 'a', 'b' 'c' %}"
|
||||||
|
template4 = "#{assignments}{% cycle n e: 'a', 'b', 'c' %}"
|
||||||
|
template5 = "#{assignments}{% cycle n e 'a', 'b', 'c' %}"
|
||||||
|
|
||||||
|
[:lax, :strict].each do |mode|
|
||||||
|
with_error_mode(mode) do
|
||||||
|
assert_template_result("a", template1)
|
||||||
|
assert_template_result("a", template2)
|
||||||
|
assert_template_result("a", template3)
|
||||||
|
assert_template_result("N", template4)
|
||||||
|
assert_template_result("N", template5)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
with_error_mode(:rigid) do
|
||||||
|
error1 = assert_raises(Liquid::SyntaxError) { Template.parse(template1) }
|
||||||
|
error2 = assert_raises(Liquid::SyntaxError) { Template.parse(template2) }
|
||||||
|
error3 = assert_raises(Liquid::SyntaxError) { Template.parse(template3) }
|
||||||
|
error4 = assert_raises(Liquid::SyntaxError) { Template.parse(template4) }
|
||||||
|
error5 = assert_raises(Liquid::SyntaxError) { Template.parse(template5) }
|
||||||
|
|
||||||
|
expected_error = /Expected end_of_string but found/
|
||||||
|
|
||||||
|
assert_match(expected_error, error1.message)
|
||||||
|
assert_match(expected_error, error2.message)
|
||||||
|
assert_match(expected_error, error3.message)
|
||||||
|
assert_match(expected_error, error4.message)
|
||||||
|
assert_match(expected_error, error5.message)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user