From 211799450d25c3e6a42a48a5146af5bed78cd66d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 9 Jun 2010 22:48:50 +0200 Subject: [PATCH] Ensure show exceptions middleware properly filters backtrace before logging. --- .../middleware/show_exceptions.rb | 2 +- railties/test/application/middleware_test.rb | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb index 8a2d8cd077..0a6d2bfc8a 100644 --- a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb @@ -135,7 +135,7 @@ module ActionDispatch ActiveSupport::Deprecation.silence do message = "\n#{exception.class} (#{exception.message}):\n" message << exception.annoted_source_code if exception.respond_to?(:annoted_source_code) - message << exception.backtrace.join("\n ") + message << " " << application_trace(exception).join("\n ") logger.fatal("#{message}\n\n") end end diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index aa75fed793..999f666a64 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -1,4 +1,5 @@ require 'isolation/abstract_unit' +require 'stringio' module ApplicationTests class MiddlewareTest < Test::Unit::TestCase @@ -163,6 +164,25 @@ module ApplicationTests assert_equal "1.1.1.1", remote_ip("REMOTE_ADDR" => "4.2.42.42,1.1.1.1") end + test "show exceptions middleware filter backtrace before logging" do + my_middleware = Struct.new(:app) do + def call(env) + raise "Failure" + end + end + + make_basic_app do |app| + app.config.middleware.use my_middleware + end + + stringio = StringIO.new + Rails.logger = Logger.new(stringio) + + env = Rack::MockRequest.env_for("/") + Rails.application.call(env) + assert_no_match(/action_dispatch/, stringio.string) + end + private def boot!