mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
The if tag now raises Liquid::SyntaxError rather than a generic RuntimeError for syntax problems.
This commit is contained in:
@@ -51,14 +51,14 @@ module Liquid
|
|||||||
else
|
else
|
||||||
|
|
||||||
expressions = markup.split(/\b(and|or)\b/).reverse
|
expressions = markup.split(/\b(and|or)\b/).reverse
|
||||||
raise SyntaxHelp unless expressions.shift =~ Syntax
|
raise(SyntaxError, SyntaxHelp) unless expressions.shift =~ Syntax
|
||||||
|
|
||||||
condition = Condition.new($1, $2, $3)
|
condition = Condition.new($1, $2, $3)
|
||||||
|
|
||||||
while not expressions.empty?
|
while not expressions.empty?
|
||||||
operator = expressions.shift
|
operator = expressions.shift
|
||||||
|
|
||||||
raise SyntaxHelp unless expressions.shift.to_s =~ Syntax
|
raise(SyntaxError, SyntaxHelp) unless expressions.shift.to_s =~ Syntax
|
||||||
|
|
||||||
new_condition = Condition.new($1, $2, $3)
|
new_condition = Condition.new($1, $2, $3)
|
||||||
new_condition.send(operator.to_sym, condition)
|
new_condition.send(operator.to_sym, condition)
|
||||||
|
|||||||
@@ -116,6 +116,10 @@ class IfElseTest < Test::Unit::TestCase
|
|||||||
assert_raise(SyntaxError){ assert_template_result('', '{% if jerry == 1 %}')}
|
assert_raise(SyntaxError){ assert_template_result('', '{% if jerry == 1 %}')}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_syntax_error_no_expression
|
||||||
|
assert_raise(SyntaxError) { assert_template_result('', '{% if %}') }
|
||||||
|
end
|
||||||
|
|
||||||
def test_if_with_custom_condition
|
def test_if_with_custom_condition
|
||||||
Condition.operators['contains'] = :[]
|
Condition.operators['contains'] = :[]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user