Skip to content

Commit 8cc0f32

Browse files
[12.x] Add missing separators to Stringable::ucwords (#57688)
* add missing separators to Stringable `ucwords` * Update Stringable.php --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent a7e7c8c commit 8cc0f32

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/Illuminate/Support/Stringable.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,11 +1110,12 @@ public function ucfirst()
11101110
/**
11111111
* Capitalize the first character of each word in a string.
11121112
*
1113+
* @param string $separators
11131114
* @return static
11141115
*/
1115-
public function ucwords()
1116+
public function ucwords($separators = " \t\r\n\f\v")
11161117
{
1117-
return new static(Str::ucwords($this->value));
1118+
return new static(Str::ucwords($this->value, $separators));
11181119
}
11191120

11201121
/**

tests/Support/SupportStringableTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,16 @@ public function testCanBeLimitedByWords()
180180
$this->assertSame('Taylor Otwell', (string) $this->stringable('Taylor Otwell')->words(3));
181181
}
182182

183+
public function testUcwords()
184+
{
185+
$this->assertSame('Laravel', (string) $this->stringable('laravel')->ucwords());
186+
$this->assertSame('Laravel Framework', (string) $this->stringable('laravel framework')->ucwords());
187+
$this->assertSame('Laravel-Framework', (string) $this->stringable('laravel-framework')->ucwords('-'));
188+
$this->assertSame('Мама', (string) $this->stringable('мама')->ucwords());
189+
$this->assertSame('Мама Мыла Раму', (string) $this->stringable('мама мыла раму')->ucwords());
190+
$this->assertSame('JJ Watt', (string) $this->stringable('JJ watt')->ucwords());
191+
}
192+
183193
public function testUnless()
184194
{
185195
$this->assertSame('unless false', (string) $this->stringable('unless')->unless(false, function ($stringable, $value) {

0 commit comments

Comments
 (0)