diff --git a/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php b/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php index 15f5620a4e85..14ac28f50873 100644 --- a/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php +++ b/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php @@ -53,7 +53,7 @@ protected function transform($key, $value) return $value; } - return preg_replace('~^[\s​]+|[\s​]+$~u', '', $value) ?? trim($value); + return preg_replace('~^[\s\x{FEFF}\x{200B}]+|[\s\x{FEFF}\x{200B}]+$~u', '', $value) ?? trim($value); } /** diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index 8b23bfad5edb..5bc854dc67a5 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -1073,7 +1073,7 @@ public static function snake($value, $delimiter = '_') */ public static function squish($value) { - return preg_replace('~(\s|\x{3164})+~u', ' ', preg_replace('~^[\s]+|[\s]+$~u', '', $value)); + return preg_replace('~(\s|\x{3164})+~u', ' ', preg_replace('~^[\s\x{FEFF}]+|[\s\x{FEFF}]+$~u', '', $value)); } /** diff --git a/tests/Http/Middleware/TrimStringsTest.php b/tests/Http/Middleware/TrimStringsTest.php index 0a7e3bcf7903..cbc4109c5d02 100644 --- a/tests/Http/Middleware/TrimStringsTest.php +++ b/tests/Http/Middleware/TrimStringsTest.php @@ -16,13 +16,13 @@ public function test_no_zero_width_space_character_returns_the_same_string() $request = new Request; $request->merge([ - 'title' => 'This title does not contains any zero-width space', + 'title' => 'This title does not contain any zero-width space', ]); $middleware = new TrimStrings; $middleware->handle($request, function ($req) { - $this->assertEquals('This title does not contains any zero-width space', $req->title); + $this->assertEquals('This title does not contain any zero-width space', $req->title); }); } @@ -34,13 +34,13 @@ public function test_leading_zero_width_space_character_is_trimmed() $request = new Request; $request->merge([ - 'title' => '​This title contains a zero-width space at the begining', + 'title' => '​This title contains a zero-width space at the beginning', ]); $middleware = new TrimStrings; $middleware->handle($request, function ($req) { - $this->assertEquals('This title contains a zero-width space at the begining', $req->title); + $this->assertEquals('This title contains a zero-width space at the beginning', $req->title); }); } @@ -70,13 +70,13 @@ public function test_leading_zero_width_non_breakable_space_character_is_trimmed $request = new Request; $request->merge([ - 'title' => 'This title contains a zero-width non-breakable space at the begining', + 'title' => 'This title contains a zero-width non-breakable space at the beginning', ]); $middleware = new TrimStrings; $middleware->handle($request, function ($req) { - $this->assertEquals('This title contains a zero-width non-breakable space at the begining', $req->title); + $this->assertEquals('This title contains a zero-width non-breakable space at the beginning', $req->title); }); } @@ -88,13 +88,13 @@ public function test_leading_multiple_zero_width_non_breakable_space_characters_ $request = new Request; $request->merge([ - 'title' => 'This title contains a zero-width non-breakable space at the begining', + 'title' => 'This title contains a zero-width non-breakable space at the beginning', ]); $middleware = new TrimStrings; $middleware->handle($request, function ($req) { - $this->assertEquals('This title contains a zero-width non-breakable space at the begining', $req->title); + $this->assertEquals('This title contains a zero-width non-breakable space at the beginning', $req->title); }); } @@ -106,13 +106,13 @@ public function test_combination_of_leading_and_trailing_zero_width_non_breakabl $request = new Request; $request->merge([ - 'title' => '​This title contains a combination of zero-width non-breakable space and zero-width spaces characters at the begining and the end​', + 'title' => '​This title contains a combination of zero-width non-breakable space and zero-width spaces characters at the beginning and the end​', ]); $middleware = new TrimStrings; $middleware->handle($request, function ($req) { - $this->assertEquals('This title contains a combination of zero-width non-breakable space and zero-width spaces characters at the begining and the end', $req->title); + $this->assertEquals('This title contains a combination of zero-width non-breakable space and zero-width spaces characters at the beginning and the end', $req->title); }); } }