mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixing method coercion in error404 so it only coerces CakeExceptions.
Test Added.
This commit is contained in:
parent
534f6006f8
commit
1f30c06695
2 changed files with 25 additions and 1 deletions
|
@ -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);
|
||||||
|
|
|
@ -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
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue