Skip to content

Commit

Permalink
fallback slug separator to '-' in case of alphanumeric separator
Browse files Browse the repository at this point in the history
  • Loading branch information
faissaloux committed Feb 3, 2025
1 parent 53091c2 commit 1406f11
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Illuminate/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,7 @@ public static function singular($value)
public static function slug($title, $separator = '-', $language = 'en', $dictionary = ['@' => 'at'])
{
$title = $language ? static::ascii($title, $language) : $title;
$separator = ctype_alnum($separator) ? '-' : $separator;

// Convert all dashes/underscores into separator
$flip = $separator === '-' ? '_' : '-';
Expand Down
4 changes: 4 additions & 0 deletions tests/Support/SupportStringableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,10 @@ public function testSlug()
$this->assertSame('sometext', (string) $this->stringable('some text')->slug(''));
$this->assertSame('', (string) $this->stringable('')->slug(''));
$this->assertSame('', (string) $this->stringable('')->slug());
$this->assertSame('hello-world', (string) $this->stringable('hello world')->slug('eb'));
$this->assertSame('hello-world', (string) $this->stringable('hello world')->slug('e'));
$this->assertSame('hello-world', (string) $this->stringable('hello world')->slug('2'));
$this->assertSame('hello-world', (string) $this->stringable('hello world')->slug('2'));
}

public function testSquish()
Expand Down

0 comments on commit 1406f11

Please sign in to comment.