改行コードを正規化する処理をミドルウェア化
This commit is contained in:
parent
2dd5cbd072
commit
a35b58eb47
@ -35,6 +35,7 @@ class Kernel extends HttpKernel
|
|||||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||||
|
\App\Http\Middleware\NormalizeLineEnding::class,
|
||||||
],
|
],
|
||||||
|
|
||||||
'api' => [
|
'api' => [
|
||||||
|
30
app/Http/Middleware/NormalizeLineEnding.php
Normal file
30
app/Http/Middleware/NormalizeLineEnding.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* リクエスト内の改行コードを正規化する。
|
||||||
|
* @package App\Http\Middleware
|
||||||
|
*/
|
||||||
|
class NormalizeLineEnding
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Closure $next
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle($request, Closure $next)
|
||||||
|
{
|
||||||
|
$newInput = [];
|
||||||
|
foreach ($request->input() as $key => $value) {
|
||||||
|
$newInput[$key] = str_replace(["\r\n", "\r"], "\n", $value);
|
||||||
|
}
|
||||||
|
$request->replace($newInput);
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user