ErrorHandler: Remove some form fields before serialization

This commit is contained in:
Igor Scheller 2019-07-21 13:24:47 +02:00
parent b03102e3c6
commit 51a3c6eb44
2 changed files with 17 additions and 2 deletions

View File

@ -6,6 +6,7 @@ use Engelsystem\Http\Exceptions\HttpException;
use Engelsystem\Http\Exceptions\ValidationException;
use Engelsystem\Http\Request;
use Engelsystem\Http\Response;
use Illuminate\Support\Arr;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
@ -20,6 +21,16 @@ class ErrorHandler implements MiddlewareInterface
/** @var string */
protected $viewPrefix = 'errors/';
/**
* A list of inputs that are not saved from form input
*
* @var array
*/
protected $formIgnore = [
'password',
'password_confirmation',
];
/**
* @param TwigLoader $loader
*/
@ -58,7 +69,7 @@ class ErrorHandler implements MiddlewareInterface
)
);
$session->set('form-data', $request->request->all());
$session->set('form-data', Arr::except($request->request->all(), $this->formIgnore));
}
}

View File

@ -176,7 +176,11 @@ class ErrorHandlerTest extends TestCase
$session = new Session(new MockArraySessionStorage());
$session->set('errors', ['validation' => ['foo' => ['validation.foo.required']]]);
$request = Request::create('/foo/bar', 'POST', ['foo' => 'bar']);
$request = Request::create(
'/foo/bar',
'POST',
['foo' => 'bar', 'password' => 'Test123', 'password_confirmation' => 'Test1234']
);
$request->setSession($session);
/** @var Application $app */