From c34aba4d1a4adb8f9dbb24afb35852602d920214 Mon Sep 17 00:00:00 2001 From: Mike Angell Date: Sat, 31 Aug 2019 19:55:04 +1000 Subject: [PATCH] Add blank scope constant --- lib/liquid/context.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/liquid/context.rb b/lib/liquid/context.rb index d74b0ce8..87126a9a 100644 --- a/lib/liquid/context.rb +++ b/lib/liquid/context.rb @@ -15,6 +15,8 @@ module Liquid attr_reader :scopes, :errors, :registers, :environments, :resource_limits, :static_registers, :static_environments attr_accessor :exception_renderer, :template_name, :partial, :global_filter, :strict_variables, :strict_filters + BLANK_SCOPE = {} + # rubocop:disable Metrics/ParameterLists def self.build(environments: {}, outer_scope: {}, registers: {}, rethrow_errors: false, resource_limits: nil, static_registers: {}, static_environments: {}) new(environments, outer_scope, registers, rethrow_errors, resource_limits, static_registers, static_environments) @@ -194,7 +196,7 @@ module Liquid scope = (index = @scopes.find_index { |s| s.key?(key) }) && @scopes[index] scope ||= (index = @environments.find_index { |s| s.key?(key) || !s.default_proc.nil? }) && @environments[index] scope ||= (index = @static_environments.find_index { |s| s.key?(key) }) && @static_environments[index] - scope ||= {} + scope ||= BLANK_SCOPE variable = lookup_and_evaluate(scope, key, raise_on_not_found: raise_on_not_found).to_liquid variable.context = self if variable.respond_to?(:context=)