8000 [9.x] Fix TrimStrings middleware with non-UTF8 characters (#42065) · laravel/framework@4b233ad · GitHub
[go: up one dir, main page]

Skip to content

Commit 4b233ad

Browse files
authored
[9.x] Fix TrimStrings middleware with non-UTF8 characters (#42065)
* Fix TrimStrings middleware with non-UTF8 values * Whitespace This will trigger the tests again
1 parent 73f7cd4 commit 4b233ad

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/Illuminate/Foundation/Http/Middleware/TrimStrings.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ public function handle($request, Closure $next)
4949
*/
5050
protected function transform($key, $value)
5151
{
52-
if (in_array($key, $this->except, true)) {
52+
if (in_array($key, $this->except, true) || ! is_string($value)) {
5353
return $value;
5454
}
5555

56-
return is_string($value) ? preg_replace('~^[\s]+|[\s]+$~u', '', $value) : $value;
56+
return preg_replace('~^[\s]+|[\s]+$~u', '', $value) ?? trim($value);
5757
}
5858

5959
/**

tests/Foundation/Http/Middleware/TrimStringsTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public function testTrimStringsNBSP()
4141
'foo' => '',
4242
'bar' => '  だ   ',
4343
'baz' => '  ム   ',
44+
'binary' => " \xE9 ",
4445
]);
4546
$symfonyRequest->server->set('REQUEST_METHOD', 'GET');
4647
$request = Request::createFromBase($symfonyRequest);
@@ -52,6 +53,7 @@ public function testTrimStringsNBSP()
5253
$this->assertSame('', $request->get('foo'));
5354
$this->assertSame('', $request->get('bar'));
5455
$this->assertSame('', $request->get('baz'));
56+
$this->assertSame("\xE9", $request->get('binary'));
5557
});
5658
}
5759
}

0 commit comments

Comments
 (0)
0