mirror of
https://github.com/kemko/liquid.git
synced 2026-01-01 15:55:40 +03:00
Avoid an exception from checking if a string contains a non-string.
This commit is contained in:
@@ -16,7 +16,12 @@ module Liquid
|
||||
'>='.freeze => :>=,
|
||||
'<='.freeze => :<=,
|
||||
'contains'.freeze => lambda do |cond, left, right|
|
||||
left && right && left.respond_to?(:include?) ? left.include?(right) : false
|
||||
if left && right && left.respond_to?(:include?)
|
||||
right = right.to_s if left.is_a?(String)
|
||||
left.include?(right)
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
|
||||
@@ -85,6 +85,11 @@ class ConditionUnitTest < Minitest::Test
|
||||
assert_evalutes_false 1, 'contains', 0
|
||||
end
|
||||
|
||||
def test_contains_with_string_left_operand_coerces_right_operand_to_string
|
||||
assert_evalutes_true ' 1 ', 'contains', 1
|
||||
assert_evalutes_false ' 1 ', 'contains', 2
|
||||
end
|
||||
|
||||
def test_or_condition
|
||||
condition = Condition.new(1, '==', 2)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user