mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-18 02:10:41 -07:00
Import Array and Hash tests, and make == blank match behaviour with AS
When ActiveSupport isn't loaded, `[] == blank` is false, but when it is loaded, it (correctly?) matches the behaviour of `[] == empty`. I think it's fair to say the intended behaviour is for == blank to match the behaviour of when AS is loaded, so let's just special-case this. We also import a bunch of Array and Hash tests here.
This commit is contained in:
@@ -112,6 +112,8 @@ module Liquid
|
||||
if left.is_a?(MethodLiteral)
|
||||
if right.respond_to?(left.method_name)
|
||||
return right.send(left.method_name)
|
||||
elsif (res = fallback_simulation_of_active_support(left.method_name, right))
|
||||
return res
|
||||
else
|
||||
return nil
|
||||
end
|
||||
@@ -120,6 +122,8 @@ module Liquid
|
||||
if right.is_a?(MethodLiteral)
|
||||
if left.respond_to?(right.method_name)
|
||||
return left.send(right.method_name)
|
||||
elsif (res = fallback_simulation_of_active_support(right.method_name, left))
|
||||
return res
|
||||
else
|
||||
return nil
|
||||
end
|
||||
@@ -128,6 +132,17 @@ module Liquid
|
||||
left == right
|
||||
end
|
||||
|
||||
# ActiveSupport creates #blank? as an alias for #empty? on Hash and Array.
|
||||
# Without this simulation, [] == blank behaves differently when AS is loaded vs. not.
|
||||
def fallback_simulation_of_active_support(method_name, obj)
|
||||
return nil unless method_name == :blank?
|
||||
|
||||
case obj
|
||||
when Array, Hash
|
||||
obj.empty?
|
||||
end # else nil
|
||||
end
|
||||
|
||||
def interpret_condition(left, right, op, context)
|
||||
# If the operator is empty this means that the decision statement is just
|
||||
# a single variable. We can just poll this variable from the context and
|
||||
|
||||
Reference in New Issue
Block a user