From 4ff26cd70766fdf4953a059d8dd30ee5723a77ad Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Tue, 1 Dec 2020 17:52:00 -0500 Subject: [PATCH 1/2] Use the same context class for isolated subcontexts for the require tag --- lib/liquid/context.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/liquid/context.rb b/lib/liquid/context.rb index 29fa196..0103656 100644 --- a/lib/liquid/context.rb +++ b/lib/liquid/context.rb @@ -135,7 +135,7 @@ module Liquid def new_isolated_subcontext check_overflow - Context.build( + self.class.build( resource_limits: resource_limits, static_environments: static_environments, registers: StaticRegisters.new(registers) From 40a9b72b3cebb640dca02dc13b91031e9ddc2bc8 Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Wed, 2 Dec 2020 09:09:40 -0500 Subject: [PATCH 2/2] Allow a block to finish context init before squashing instance assigns Liquid::Context#squash_instance_assigns_with_environments can result in Proc objects in the environment to be eagerly evaluated. So it should be possible to finish initializing the context object before this is done. Allowing a block to be used for this purpose avoids the need to add additional parameters for this purpose. --- lib/liquid/context.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/liquid/context.rb b/lib/liquid/context.rb index 0103656..605fdde 100644 --- a/lib/liquid/context.rb +++ b/lib/liquid/context.rb @@ -18,8 +18,8 @@ module Liquid attr_accessor :exception_renderer, :template_name, :partial, :global_filter, :strict_variables, :strict_filters # rubocop:disable Metrics/ParameterLists - def self.build(environments: {}, outer_scope: {}, registers: {}, rethrow_errors: false, resource_limits: nil, static_environments: {}) - new(environments, outer_scope, registers, rethrow_errors, resource_limits, static_environments) + def self.build(environments: {}, outer_scope: {}, registers: {}, rethrow_errors: false, resource_limits: nil, static_environments: {}, &block) + new(environments, outer_scope, registers, rethrow_errors, resource_limits, static_environments, &block) end def initialize(environments = {}, outer_scope = {}, registers = {}, rethrow_errors = false, resource_limits = nil, static_environments = {}) @@ -44,6 +44,8 @@ module Liquid self.exception_renderer = Liquid::RAISE_EXCEPTION_LAMBDA end + yield self if block_given? + # Do this last, since it could result in this object being passed to a Proc in the environment squash_instance_assigns_with_environments end