File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -184,7 +184,7 @@ def [](expression)
184184 end
185185
186186 def key? ( key )
187- self [ key ] != nil
187+ find_variable ( key , raise_on_not_found : false ) != nil
188188 end
189189
190190 def evaluate ( object )
Original file line number Diff line number Diff line change @@ -639,6 +639,21 @@ def test_has_key_will_not_add_an_error_for_missing_keys
639639 end
640640 end
641641
642+ def test_key_lookup_will_raise_for_missing_keys_when_strict_variables_is_enabled
643+ context = Context . new
644+ context . strict_variables = true
645+ assert_raises ( Liquid ::UndefinedVariable ) do
646+ context [ 'unknown' ]
647+ end
648+ end
649+
650+ def test_has_key_will_not_raise_for_missing_keys_when_strict_variables_is_enabled
651+ context = Context . new
652+ context . strict_variables = true
653+ refute ( context . key? ( 'unknown' ) )
654+ assert_empty ( context . errors )
655+ end
656+
642657 def test_context_always_uses_static_registers
643658 registers = {
644659 my_register : :my_value ,
You can’t perform that action at this time.
0 commit comments