mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix "Stack Level Too Deep" error when rendering recursive partials
When rendering recursive partial Action View is trying to generate the view digest infinitly causing a stack level error. Fixes #11340
This commit is contained in:
parent
a67cc28311
commit
09f6fe1cd4
5 changed files with 40 additions and 3 deletions
|
@ -1,3 +1,9 @@
|
|||
* Fix "Stack Level Too Deep" error when redering recursive partials.
|
||||
|
||||
Fixes #11340.
|
||||
|
||||
*Rafael Mendonça França*
|
||||
|
||||
* Added an `enforce_utf8` hash option for `form_tag` method.
|
||||
|
||||
Control to output a hidden input tag with name `utf8` without monkey
|
||||
|
|
|
@ -7,10 +7,14 @@ module ActionView
|
|||
@@cache = ThreadSafe::Cache.new
|
||||
|
||||
def self.digest(name, format, finder, options = {})
|
||||
cache_key = [name, format] + Array.wrap(options[:dependencies])
|
||||
@@cache[cache_key.join('.')] ||= begin
|
||||
cache_key = ([name, format] + Array.wrap(options[:dependencies])).join('.')
|
||||
@@cache.fetch(cache_key) do
|
||||
@@cache[cache_key] ||= nil if options[:partial] # Prevent re-entry
|
||||
|
||||
klass = options[:partial] || name.include?("/_") ? PartialDigestor : Digestor
|
||||
klass.new(name, format, finder, options).digest
|
||||
digest = klass.new(name, format, finder, options).digest
|
||||
|
||||
@@cache[cache_key] = digest # Store the value
|
||||
end
|
||||
end
|
||||
|
||||
|
|
1
actionview/test/fixtures/digestor/level/_recursion.html.erb
vendored
Normal file
1
actionview/test/fixtures/digestor/level/_recursion.html.erb
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
<%= render 'recursion' %>
|
1
actionview/test/fixtures/digestor/level/recursion.html.erb
vendored
Normal file
1
actionview/test/fixtures/digestor/level/recursion.html.erb
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
<%= render 'recursion' %>
|
|
@ -95,6 +95,31 @@ class TemplateDigestorTest < ActionView::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_recursion_in_renders
|
||||
assert digest("level/recursion") # assert recursion is possible
|
||||
assert_not_nil digest("level/recursion") # assert digest is stored
|
||||
end
|
||||
|
||||
def test_chaning_the_top_templete_on_recursion
|
||||
assert digest("level/recursion") # assert recursion is possible
|
||||
|
||||
assert_digest_difference("level/recursion") do
|
||||
change_template("level/recursion")
|
||||
end
|
||||
|
||||
assert_not_nil digest("level/recursion") # assert digest is stored
|
||||
end
|
||||
|
||||
def test_chaning_the_partial_templete_on_recursion
|
||||
assert digest("level/recursion") # assert recursion is possible
|
||||
|
||||
assert_digest_difference("level/recursion") do
|
||||
change_template("level/_recursion")
|
||||
end
|
||||
|
||||
assert_not_nil digest("level/recursion") # assert digest is stored
|
||||
end
|
||||
|
||||
def test_dont_generate_a_digest_for_missing_templates
|
||||
assert_equal '', digest("nothing/there")
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue