mirror of
https://github.com/kemko/liquid.git
synced 2026-01-05 01:35:41 +03:00
Create new resource_limits hash on Template initialization
This commit is contained in:
@@ -50,6 +50,7 @@ module Liquid
|
||||
|
||||
# creates a new <tt>Template</tt> from an array of tokens. Use <tt>Template.parse</tt> instead
|
||||
def initialize
|
||||
@resource_limits = {}
|
||||
end
|
||||
|
||||
# Parse source code.
|
||||
@@ -88,7 +89,7 @@ module Liquid
|
||||
#
|
||||
def render(*args)
|
||||
return '' if @root.nil?
|
||||
|
||||
|
||||
context = case args.first
|
||||
when Liquid::Context
|
||||
args.shift
|
||||
|
||||
@@ -112,4 +112,12 @@ class TemplateTest < Test::Unit::TestCase
|
||||
assert_equal "Liquid error: Memory limits exceeded", t.render()
|
||||
assert t.resource_limits[:reached]
|
||||
end
|
||||
|
||||
def test_resource_limits_hash_in_template_gets_updated_even_if_no_limits_are_set
|
||||
t = Template.parse("{% for a in (1..100) %} {% assign foo = 1 %} {% endfor %}")
|
||||
t.render()
|
||||
assert t.resource_limits[:assign_score_current] > 0
|
||||
assert t.resource_limits[:render_score_current] > 0
|
||||
assert t.resource_limits[:render_length_current] > 0
|
||||
end
|
||||
end # TemplateTest
|
||||
|
||||
Reference in New Issue
Block a user