Skip to content

Commit 644c9d8

Browse files
authored
improve unicode support on Str::squish() (#41877)
1 parent d2dce63 commit 644c9d8

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/Illuminate/Support/Str.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ public static function snake($value, $delimiter = '_')
889889
*/
890890
public static function squish($value)
891891
{
892-
return preg_replace('/\s+/', ' ', trim($value));
892+
return preg_replace('~\s+~u', ' ', preg_replace('~^\s+|\s+$~u', '', $value));
893893
}
894894

895895
/**

tests/Support/SupportStrTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,12 @@ public function testSquish()
547547
php
548548
framework
549549
'));
550+
$this->assertSame('laravel php framework', Str::squish('   laravel   php   framework   '));
551+
$this->assertSame('123', Str::squish('  123   '));
552+
$this->assertSame('', Str::squish(''));
553+
$this->assertSame('', Str::squish(''));
554+
$this->assertSame('', Str::squish('  だ   '));
555+
$this->assertSame('', Str::squish('  ム   '));
550556
}
551557

552558
public function testStudly()

tests/Support/SupportStringableTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,12 @@ public function testSquish()
620620
with
621621
spaces
622622
')->squish());
623+
$this->assertSame('laravel php framework', (string) $this->stringable('   laravel   php   framework   ')->squish());
624+
$this->assertSame('123', (string) $this->stringable('  123   ')->squish());
625+
$this->assertSame('', (string) $this->stringable('')->squish());
626+
$this->assertSame('', (string) $this->stringable('')->squish());
627+
$this->assertSame('', (string) $this->stringable('  だ   ')->squish());
628+
$this->assertSame('', (string) $this->stringable('  ム   ')->squish());
623629
}
624630

625631
public function testStart()

0 commit comments

Comments
 (0)