Prevent SelfDrop context mutation across render boundaries (#2082)

This commit is contained in:
Guilherme Carreiro
2026-05-20 09:34:37 +02:00
committed by GitHub
parent 1954a2655c
commit 742ac3dbf5
3 changed files with 108 additions and 6 deletions
+6 -4
View File
@@ -16,23 +16,25 @@ module Liquid
# then the local value takes precedence over the `self` object.
# @liquid_access global
class SelfDrop < Drop
def initialize(context)
def initialize(self_context)
super()
@context = context
@self_context = self_context
end
def [](key)
@context.find_variable(key)
@self_context.find_variable(key)
rescue UndefinedVariable
nil
end
def key?(key)
@context.variable_defined?(key)
@self_context.variable_defined?(key)
end
def to_liquid
self
end
undef context=
end
end
+4 -2
View File
@@ -151,8 +151,10 @@ module Liquid
c
when Liquid::Drop
drop = args.shift
drop.context = Context.new([drop, assigns], instance_assigns, registers, @rethrow_errors, @resource_limits, {}, @environment)
drop = args.shift
c = Context.new([drop, assigns], instance_assigns, registers, @rethrow_errors, @resource_limits, {}, @environment)
drop.context = c if drop.respond_to?(:context=)
c
when Hash
Context.new([args.shift, assigns], instance_assigns, registers, @rethrow_errors, @resource_limits, {}, @environment)
when nil