Don't raise if no variable found when using context.key?

Previously if you set `strict_variables` to `true` on the context using
`key?('key_name')` would raise a `Liquid::UndefinedVariable` error.
Raising this error makes sense if you're trying to access the variable
directly with something like  `context['key_name']` but by using `key?`
you're safely checking if it exists first.

You should be able to enable `strict_variables` and use `key?` in
combination with each other to ensure code safety.
This commit is contained in:
Gray Gilmore
2025-10-30 15:33:07 -07:00
parent 248f3a412f
commit 9973f3399e
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)