mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Fix resource counting bug with respond_to?(:length)
This commit is contained in:
+1
-1
@@ -135,7 +135,7 @@ module Liquid
|
||||
end
|
||||
|
||||
token_output = (token.respond_to?(:render) ? token.render(context) : token)
|
||||
context.resource_limits[:render_length_current] += (token_output.respond_to?(:length) ? token_output.length : 1)
|
||||
context.increment_used_resources(:render_length_current, token_output)
|
||||
if context.resource_limits_reached?
|
||||
context.resource_limits[:reached] = true
|
||||
raise MemoryError.new("Memory limits exceeded")
|
||||
|
||||
@@ -28,6 +28,14 @@ module Liquid
|
||||
@filters = []
|
||||
end
|
||||
|
||||
def increment_used_resources(key, obj)
|
||||
@resource_limits[key] += if obj.class.ancestors & [ String, Array, Hash ] != []
|
||||
obj.length
|
||||
else
|
||||
1
|
||||
end
|
||||
end
|
||||
|
||||
def resource_limits_reached?
|
||||
(@resource_limits[:render_length_limit] && @resource_limits[:render_length_current] > @resource_limits[:render_length_limit]) ||
|
||||
(@resource_limits[:render_score_limit] && @resource_limits[:render_score_current] > @resource_limits[:render_score_limit] ) ||
|
||||
|
||||
@@ -25,7 +25,7 @@ module Liquid
|
||||
def render(context)
|
||||
val = @from.render(context)
|
||||
context.scopes.last[@to] = val
|
||||
context.resource_limits[:assign_score_current] += (val.respond_to?(:length) ? val.length : 1)
|
||||
context.increment_used_resources(:assign_score_current, val)
|
||||
''
|
||||
end
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ module Liquid
|
||||
def render(context)
|
||||
output = super
|
||||
context.scopes.last[@to] = output
|
||||
context.resource_limits[:assign_score_current] += (output.respond_to?(:length) ? output.length : 1)
|
||||
context.increment_used_resources(:assign_score_current, output)
|
||||
''
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user