mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-19 02:40:41 -07:00
Merge pull request #2007 from Shopify/gg-change-key-behavior
Don't raise if no variable found when `using context.key?` with `strict_variables`
This commit is contained in:
@@ -184,7 +184,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def key?(key)
|
def key?(key)
|
||||||
self[key] != nil
|
find_variable(key, raise_on_not_found: false) != nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def evaluate(object)
|
def evaluate(object)
|
||||||
|
|||||||
@@ -639,6 +639,21 @@ class ContextTest < Minitest::Test
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_key_lookup_will_raise_for_missing_keys_when_strict_variables_is_enabled
|
||||||
|
context = Context.new
|
||||||
|
context.strict_variables = true
|
||||||
|
assert_raises(Liquid::UndefinedVariable) do
|
||||||
|
context['unknown']
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_has_key_will_not_raise_for_missing_keys_when_strict_variables_is_enabled
|
||||||
|
context = Context.new
|
||||||
|
context.strict_variables = true
|
||||||
|
refute(context.key?('unknown'))
|
||||||
|
assert_empty(context.errors)
|
||||||
|
end
|
||||||
|
|
||||||
def test_context_always_uses_static_registers
|
def test_context_always_uses_static_registers
|
||||||
registers = {
|
registers = {
|
||||||
my_register: :my_value,
|
my_register: :my_value,
|
||||||
|
|||||||
Reference in New Issue
Block a user