From 327660eb7f7e3e7339dd1fead1404bda10e09c13 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Mon, 13 Aug 2012 18:34:00 +0000 Subject: [PATCH] Respond with 404 on ActionView::MissingTemplate (#11503). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10204 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/application_controller.rb | 15 ++++++++++----- test/integration/application_test.rb | 5 +++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5a1774c04..d6efa4124 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -39,6 +39,7 @@ class ApplicationController < ActionController::Base rescue_from ActionController::InvalidAuthenticityToken, :with => :invalid_authenticity_token rescue_from ::Unauthorized, :with => :deny_access + rescue_from ::ActionView::MissingTemplate, :with => :missing_template include Redmine::Search::Controller include Redmine::MenuManager::MenuController @@ -352,13 +353,17 @@ class ApplicationController < ActionController::Base format.html { render :template => 'common/error', :layout => use_layout, :status => @status } - format.atom { head @status } - format.xml { head @status } - format.js { head @status } - format.json { head @status } + format.any { head @status } end end - + + # Handler for ActionView::MissingTemplate exception + def missing_template + logger.warn "Missing template, responding with 404" + @project = nil + render_404 + end + # Filter for actions that provide an API response # but have no HTML representation for non admin users def require_admin_or_api_request diff --git a/test/integration/application_test.rb b/test/integration/application_test.rb index 09ffd070c..fe4059afb 100644 --- a/test/integration/application_test.rb +++ b/test/integration/application_test.rb @@ -60,4 +60,9 @@ class ApplicationTest < ActionController::IntegrationTest assert_response 200 assert_nil session[:user_id] end + + def test_missing_template_should_respond_with_404 + get '/login.png' + assert_response 404 + end end