Fixing method coercion in error404 so it only coerces CakeExceptions.

Test Added.
This commit is contained in:
mark_story 2010-08-29 23:39:28 -04:00
parent 534f6006f8
commit 1f30c06695
2 changed files with 25 additions and 1 deletions

View file

@ -179,7 +179,7 @@ class ErrorHandler {
*/ */
public function error404($error) { public function error404($error) {
$message = $error->getMessage(); $message = $error->getMessage();
if (Configure::read('debug') == 0) { if (Configure::read('debug') == 0 && $error instanceof CakeException) {
$message = __('Not Found'); $message = __('Not Found');
} }
$url = Router::normalize($this->controller->request->here); $url = Router::normalize($this->controller->request->here);

View file

@ -376,6 +376,30 @@ class ErrorHandlerTest extends CakeTestCase {
App::build(); App::build();
} }
/**
* test that error404 only modifies the messages on CakeExceptions.
*
* @return void
*/
function testError404OnlyChangingCakeException() {
Configure::write('debug', 0);
$exception = new Error404Exception('Custom message');
$ErrorHandler = new ErrorHandler($exception);
ob_start();
$ErrorHandler->render();
$result = ob_get_clean();
$this->assertContains('Custom message', $result);
$exception = new MissingActionException(array('controller' => 'PostsController', 'action' => 'index'));
$ErrorHandler = new ErrorHandler($exception);
ob_start();
$ErrorHandler->render();
$result = ob_get_clean();
$this->assertContains('Not Found', $result);
}
/** /**
* test that error404 doesn't expose XSS * test that error404 doesn't expose XSS
* *