mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-19 19:00:39 -07:00
Fix internal liquid error when comparing hash with incompatible type (#849)
This commit is contained in:
committed by
GitHub
parent
ffb0ace303
commit
2bb3552033
@@ -110,7 +110,7 @@ module Liquid
|
|||||||
|
|
||||||
if operation.respond_to?(:call)
|
if operation.respond_to?(:call)
|
||||||
operation.call(self, left, right)
|
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
|
begin
|
||||||
left.send(operation, right)
|
left.send(operation, right)
|
||||||
rescue ::ArgumentError => e
|
rescue ::ArgumentError => e
|
||||||
|
|||||||
@@ -64,6 +64,13 @@ class ConditionUnitTest < Minitest::Test
|
|||||||
assert_evaluates_argument_error '1', '<=', 0
|
assert_evaluates_argument_error '1', '<=', 0
|
||||||
end
|
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
|
def test_contains_works_on_arrays
|
||||||
@context = Liquid::Context.new
|
@context = Liquid::Context.new
|
||||||
@context['array'] = [1, 2, 3, 4, 5]
|
@context['array'] = [1, 2, 3, 4, 5]
|
||||||
|
|||||||
Reference in New Issue
Block a user