mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-19 19:00:39 -07:00
Add optional resource usage limitations to number of rendering calls, length of rendering output and/or number of variable/capture assignments
This commit is contained in:
+9
-1
@@ -90,6 +90,9 @@ module Liquid
|
||||
|
||||
def render_all(list, context)
|
||||
output = []
|
||||
context.resource_limits[:render_length_current] = 0
|
||||
context.resource_limits[:render_score_current] += list.length
|
||||
|
||||
list.each do |token|
|
||||
# Break out if we have any unhanded interrupts.
|
||||
break if context.has_interrupt?
|
||||
@@ -103,7 +106,12 @@ module Liquid
|
||||
break
|
||||
end
|
||||
|
||||
output << (token.respond_to?(:render) ? token.render(context) : token)
|
||||
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)
|
||||
raise Liquid::MemoryError, context.resource_limits if context.resource_limits_reached?
|
||||
output << token_output
|
||||
rescue Liquid::MemoryError => e
|
||||
raise e
|
||||
rescue ::StandardError => e
|
||||
output << (context.handle_error(e))
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user