Skip to content

Commit 1406f11

Browse files
committed
fallback slug separator to '-' in case of alphanumeric separator
1 parent 53091c2 commit 1406f11

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/Illuminate/Support/Str.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,7 @@ public static function singular($value)
14641464
public static function slug($title, $separator = '-', $language = 'en', $dictionary = ['@' => 'at'])
14651465
{
14661466
$title = $language ? static::ascii($title, $language) : $title;
1467+
$separator = ctype_alnum($separator) ? '-' : $separator;
14671468

14681469
// Convert all dashes/underscores into separator
14691470
$flip = $separator === '-' ? '_' : '-';

tests/Support/SupportStringableTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,10 @@ public function testSlug()
739739
$this->assertSame('sometext', (string) $this->stringable('some text')->slug(''));
740740
$this->assertSame('', (string) $this->stringable('')->slug(''));
741741
$this->assertSame('', (string) $this->stringable('')->slug());
742+
$this->assertSame('hello-world', (string) $this->stringable('hello world')->slug('eb'));
743+
$this->assertSame('hello-world', (string) $this->stringable('hello world')->slug('e'));
744+
$this->assertSame('hello-world', (string) $this->stringable('hello world')->slug('2'));
745+
$this->assertSame('hello-world', (string) $this->stringable('hello world')->slug('2'));
742746
}
743747

744748
public function testSquish()

0 commit comments

Comments
 (0)