8000 TrimString middleware adds invisible characters (#38117) · laravel/framework@709714d · GitHub
[go: up one dir, main page]

Skip to content

Commit 709714d

Browse files
allowingjie
andauthored
TrimString middleware adds invisible characters (#38117)
Co-authored-by: jie <jie@example.com>
1 parent ab5fd4b commit 709714d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected function transform($key, $value)
5353
return $value;
5454
}
5555

56-
return is_string($value) ? trim($value) : $value;
56+
return is_string($value) ? trim($value, "  \t\n\r\0\x0B") : $value;
5757
}
5858

5959
/**

tests/Foundation/Http/Middleware/TrimStringsTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@ public function testTrimStringsIgnoringExceptAttribute()
2828
$this->assertSame(' 010 ', $request->get('bar'));
2929
});
3030
}
31+
32+
public function testTrimStringsNBSP()
33+
{
34+
$middleware = new TrimStrings;
35+
$symfonyRequest = new SymfonyRequest([
36+
// Here has some NBSP, but it still display to space.
37+
'abc' => '  123   ',
38+
]);
39+
$symfonyRequest->server->set('REQUEST_METHOD', 'GET');
40+
$request = Request::createFromBase($symfonyRequest);
41+
42+
$middleware->handle($request, function (Request $request) {
43+
$this->assertSame('123', $request->get('abc'));
44+
});
45+
}
3146
}
3247

3348
class TrimStringsWithExceptAttribute extends TrimStrings

0 commit comments

Comments
 (0)
0