Commits

jplang  committed e5d96fb

Respond with 404 on ActionView::MissingTemplate (#11503).

  • Participants
  • Parent commits 5e4c4e0

Comments (0)

Files changed (2)

File app/controllers/application_controller.rb

 
   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
       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

File test/integration/application_test.rb

     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