Fix internal liquid error when comparing hash with incompatible type (#849)

This commit is contained in:
Dylan Thacker-Smith
2017-01-16 13:13:17 -05:00
committed by GitHub
parent ffb0ace303
commit 2bb3552033
2 changed files with 8 additions and 1 deletions

View File

@@ -110,7 +110,7 @@ module Liquid
if operation.respond_to?(:call)
operation.call(self, left, right)
elsif left.respond_to?(operation) && right.respond_to?(operation)
elsif left.respond_to?(operation) && right.respond_to?(operation) && !left.is_a?(Hash) && !right.is_a?(Hash)
begin
left.send(operation, right)
rescue ::ArgumentError => e

View File

@@ -64,6 +64,13 @@ class ConditionUnitTest < Minitest::Test
assert_evaluates_argument_error '1', '<=', 0
end
def test_hash_compare_backwards_compatibility
assert_equal nil, Condition.new({}, '>', 2).evaluate
assert_equal nil, Condition.new(2, '>', {}).evaluate
assert_equal false, Condition.new({}, '==', 2).evaluate
assert_equal true, Condition.new({ 'a' => 2 }, 'contains', 'a').evaluate
end
def test_contains_works_on_arrays
@context = Liquid::Context.new
@context['array'] = [1, 2, 3, 4, 5]