From d1deb89085a53b0df95eedfcd1d230fc61876d0c Mon Sep 17 00:00:00 2001 From: Mike Angell Date: Thu, 29 Aug 2019 11:40:08 +1000 Subject: [PATCH] Remove support for fallback proc on last scope This was introduced but never actually used. The introduction of environments.last as the fallback for unfound variables means this functionality is already broken --- lib/liquid/context.rb | 24 ++++-------------------- test/integration/variable_test.rb | 5 +---- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/lib/liquid/context.rb b/lib/liquid/context.rb index 2dcc6af..7718220 100644 --- a/lib/liquid/context.rb +++ b/lib/liquid/context.rb @@ -163,27 +163,11 @@ module Liquid def find_variable(key, raise_on_not_found: true) # This was changed from find() to find_index() because this is a very hot # path and find_index() is optimized in MRI to reduce object allocation - index = @scopes.find_index { |s| s.key?(key) } - scope = @scopes[index] if index + scope = (index = @scopes.find_index { |s| s.key?(key) }) && @scopes[index] + scope ||= (index = @environments.find_index { |s| s.key?(key) }) && @environments[index] + scope ||= {} - variable = nil - - if scope.nil? - @environments.each do |e| - variable = lookup_and_evaluate(e, key, raise_on_not_found: raise_on_not_found) - # When lookup returned a value OR there is no value but the lookup also did not raise - # then it is the value we are looking for. - if !variable.nil? || @strict_variables && raise_on_not_found - scope = e - break - end - end - end - - scope ||= @environments.last || @scopes.last - variable ||= lookup_and_evaluate(scope, key, raise_on_not_found: raise_on_not_found) - - variable = variable.to_liquid + variable = lookup_and_evaluate(scope, key, raise_on_not_found: raise_on_not_found).to_liquid variable.context = self if variable.respond_to?(:context=) variable diff --git a/test/integration/variable_test.rb b/test/integration/variable_test.rb index abd6e70..54c9c72 100644 --- a/test/integration/variable_test.rb +++ b/test/integration/variable_test.rb @@ -80,10 +80,7 @@ class VariableTest < Minitest::Test assigns['test'] = 'Tobi' assert_equal 'Hello Tobi', template.render!(assigns) assigns.delete('test') - e = assert_raises(RuntimeError) do - template.render!(assigns) - end - assert_equal "Unknown variable 'test'", e.message + assert_equal "Hello ", template.render!(assigns) end def test_multiline_variable