mirror of
https://github.com/kemko/liquid.git
synced 2026-01-02 00:05:42 +03:00
Compare commits
1 Commits
superfluid
...
stack-leve
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1707980a48 |
@@ -7,6 +7,7 @@ module Liquid
|
|||||||
# c.evaluate #=> true
|
# c.evaluate #=> true
|
||||||
#
|
#
|
||||||
class Condition #:nodoc:
|
class Condition #:nodoc:
|
||||||
|
@@depth = 0
|
||||||
@@operators = {
|
@@operators = {
|
||||||
'=='.freeze => ->(cond, left, right) { cond.send(:equal_variables, left, right) },
|
'=='.freeze => ->(cond, left, right) { cond.send(:equal_variables, left, right) },
|
||||||
'!='.freeze => ->(cond, left, right) { !cond.send(:equal_variables, left, right) },
|
'!='.freeze => ->(cond, left, right) { !cond.send(:equal_variables, left, right) },
|
||||||
@@ -47,6 +48,11 @@ module Liquid
|
|||||||
when :or
|
when :or
|
||||||
result || @child_condition.evaluate(context)
|
result || @child_condition.evaluate(context)
|
||||||
when :and
|
when :and
|
||||||
|
@@depth += 1
|
||||||
|
if @@depth >= 500
|
||||||
|
@@depth = 0
|
||||||
|
raise StackLevelError, "Nesting too deep".freeze
|
||||||
|
end
|
||||||
result && @child_condition.evaluate(context)
|
result && @child_condition.evaluate(context)
|
||||||
else
|
else
|
||||||
result
|
result
|
||||||
|
|||||||
@@ -130,6 +130,17 @@ class ConditionUnitTest < Minitest::Test
|
|||||||
assert_equal false, condition.evaluate
|
assert_equal false, condition.evaluate
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_maximum_recursion_depth
|
||||||
|
condition = Condition.new(1, '==', 1)
|
||||||
|
|
||||||
|
assert_raises(Liquid::StackLevelError) do
|
||||||
|
(1..510).each do
|
||||||
|
condition.evaluate
|
||||||
|
condition.and Condition.new(2, '==', 2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_should_allow_custom_proc_operator
|
def test_should_allow_custom_proc_operator
|
||||||
Condition.operators['starts_with'] = proc { |cond, left, right| left =~ %r{^#{right}} }
|
Condition.operators['starts_with'] = proc { |cond, left, right| left =~ %r{^#{right}} }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user