diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index 8a8f1088c967..691a1d4b4716 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -889,7 +889,7 @@ public static function snake($value, $delimiter = '_') */ public static function squish($value) { - return preg_replace('/\s+/', ' ', trim($value)); + return preg_replace('~\s+~u', ' ', preg_replace('~^\s+|\s+$~u', '', $value)); } /** diff --git a/tests/Support/SupportStrTest.php b/tests/Support/SupportStrTest.php index 50c7c58743f7..ec93086caba5 100755 --- a/tests/Support/SupportStrTest.php +++ b/tests/Support/SupportStrTest.php @@ -547,6 +547,12 @@ public function testSquish() php framework ')); + $this->assertSame('laravel php framework', Str::squish('   laravel   php   framework   ')); + $this->assertSame('123', Str::squish('  123   ')); + $this->assertSame('だ', Str::squish('だ')); + $this->assertSame('ム', Str::squish('ム')); + $this->assertSame('だ', Str::squish('  だ   ')); + $this->assertSame('ム', Str::squish('  ム   ')); } public function testStudly() diff --git a/tests/Support/SupportStringableTest.php b/tests/Support/SupportStringableTest.php index 477590552304..0f0ab610cfec 100644 --- a/tests/Support/SupportStringableTest.php +++ b/tests/Support/SupportStringableTest.php @@ -620,6 +620,12 @@ public function testSquish() with spaces ')->squish()); + $this->assertSame('laravel php framework', (string) $this->stringable('   laravel   php   framework   ')->squish()); + $this->assertSame('123', (string) $this->stringable('  123   ')->squish()); + $this->assertSame('だ', (string) $this->stringable('だ')->squish()); + $this->assertSame('ム', (string) $this->stringable('ム')->squish()); + $this->assertSame('だ', (string) $this->stringable('  だ   ')->squish()); + $this->assertSame('ム', (string) $this->stringable('  ム   ')->squish()); } public function testStart()