From c155fe9a3910fe3ab2e9cabe0ceb1c44fab31d72 Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Sun, 27 Jan 2008 20:45:35 +0000 Subject: Precalculate the Backtrace of a template error to avoid raising exceptions in TemplateError#backtrace. These will abort the ruby vm. Closes #10936 [Aleksey Kondratenko] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8743 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_view/template_error.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/template_error.rb b/actionpack/lib/action_view/template_error.rb index 01b4b15550..54e4cf099d 100644 --- a/actionpack/lib/action_view/template_error.rb +++ b/actionpack/lib/action_view/template_error.rb @@ -10,6 +10,7 @@ module ActionView @base_path, @assigns, @source, @original_exception = base_path, assigns.dup, source, original_exception @file_path = file_path + @backtrace = compute_backtrace end def message @@ -72,14 +73,20 @@ module ActionView "#{source_extract}\n #{clean_backtrace.join("\n ")}\n\n" end + # don't do anything nontrivial here. Any raised exception from here becomes fatal + # (and can't be rescued). def backtrace - [ - "#{source_location.capitalize}\n\n#{source_extract(4)}\n " + - clean_backtrace.join("\n ") - ] + @backtrace end private + def compute_backtrace + [ + "#{source_location.capitalize}\n\n#{source_extract(4)}\n " + + clean_backtrace.join("\n ") + ] + end + def strip_base_path(path) stripped_path = File.expand_path(path).gsub(@base_path, "") stripped_path.gsub!(/^#{Regexp.escape File.expand_path(RAILS_ROOT)}/, '') if defined?(RAILS_ROOT) -- cgit v1.2.3