From 41de8140454fa80114fd010e0a5e06b6bc3aae83 Mon Sep 17 00:00:00 2001 From: Tobi Lutke Date: Wed, 11 Mar 2026 10:32:37 -0400 Subject: [PATCH] =?UTF-8?q?Skip=20to=5Fliquid/context=3D=20for=20primitive?= =?UTF-8?q?s=20in=20VariableLookup#evaluate\n\nResult:=20{"status":"keep",?= =?UTF-8?q?"combined=5F=C2=B5s":4334,"parse=5F=C2=B5s":3062,"render=5F?= =?UTF-8?q?=C2=B5s":1272,"allocations":25535}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/liquid/variable_lookup.rb | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/liquid/variable_lookup.rb b/lib/liquid/variable_lookup.rb index 23eb676d..743d573f 100644 --- a/lib/liquid/variable_lookup.rb +++ b/lib/liquid/variable_lookup.rb @@ -182,14 +182,23 @@ module Liquid (object.respond_to?(:fetch) && key.is_a?(Integer))) # if its a proc we will replace the entry with the proc - res = context.lookup_and_evaluate(object, key) - object = res.to_liquid + object = context.lookup_and_evaluate(object, key) + # Skip to_liquid for common primitive types (they return self) + unless object.instance_of?(String) || object.instance_of?(Integer) || object.instance_of?(Float) || + object.instance_of?(Array) || object.instance_of?(Hash) || object.nil? + object = object.to_liquid + object.context = context if object.respond_to?(:context=) + end # Some special cases. If the part wasn't in square brackets and # no key with the same name was found we interpret following calls # as commands and call them on the current object elsif lookup_command?(i) && object.respond_to?(key) - object = object.send(key).to_liquid + object = object.send(key) + unless object.instance_of?(String) || object.instance_of?(Integer) || object.instance_of?(Array) || object.nil? + object = object.to_liquid + object.context = context if object.respond_to?(:context=) + end # Handle string first/last like ActiveSupport does (returns first/last character) # ActiveSupport returns "" for empty strings, not nil @@ -203,9 +212,6 @@ module Liquid return nil unless context.strict_variables raise Liquid::UndefinedVariable, "undefined variable #{key}" end - - # If we are dealing with a drop here we have to - object.context = context if object.respond_to?(:context=) end object