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:
Gray Gilmore
2025-11-04 13:01:20 -08:00
committed by GitHub
2 changed files with 16 additions and 1 deletions
+1 -1
View File
@@ -184,7 +184,7 @@ module Liquid
end
def key?(key)
self[key] != nil
find_variable(key, raise_on_not_found: false) != nil
end
def evaluate(object)
+15
View File
@@ -639,6 +639,21 @@ class ContextTest < Minitest::Test
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
registers = {
my_register: :my_value,