Skip to content

Commit e954b99

Browse files
committed
Merge remote-tracking branch 'origin/9.x' into 9.x
2 parents 24a8828 + 9d4a5b3 commit e954b99

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/Illuminate/Support/Str.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ public static function singular($value)
10141014
* @param string|null $language
10151015
* @return string
10161016
*/
1017-
public static function slug($title, $separator = '-', $language = 'en')
1017+
public static function slug($title, $separator = '-', $language = 'en', $dictionary = ['@' => 'at'])
10181018
{
10191019
$title = $language ? static::ascii($title, $language) : $title;
10201020

@@ -1023,10 +1023,14 @@ public static function slug($title, $separator = '-', $language = 'en')
10231023

10241024
$title = preg_replace('!['.preg_quote($flip).']+!u', $separator, $title);
10251025

1026-
// Replace @ with the word 'at'
1027-
$title = str_replace('@', $separator.'at'.$separator, $title);
1026+
// Replace dictionary words
1027+
foreach ($dictionary as $key => $value) {
1028+
$dictionary[$key] = $separator.$value.$separator;
1029+
}
1030+
1031+
$title = str_replace(array_keys($dictionary), array_values($dictionary), $title);
10281032

1029-
// Remove all characters that are not the separator, letters, numbers, or whitespace.
1033+
// Remove all characters that are not the separator, letters, numbers, or whitespace
10301034
$title = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', static::lower($title));
10311035

10321036
// Replace all separator characters and whitespace by a single separator

tests/Support/SupportStrTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,13 @@ public function testSlug()
320320
$this->assertSame('sometext', Str::slug('some text', ''));
321321
$this->assertSame('', Str::slug('', ''));
322322
$this->assertSame('', Str::slug(''));
323+
$this->assertSame('bsm-allah', Str::slug('بسم الله', '-', 'en', ['allh' => 'allah']));
324+
$this->assertSame('500-dollar-bill', Str::slug('500$ bill', '-', 'en', ['$' => 'dollar']));
325+
$this->assertSame('500-dollar-bill', Str::slug('500--$----bill', '-', 'en', ['$' => 'dollar']));
326+
$this->assertSame('500-dollar-bill', Str::slug('500-$-bill', '-', 'en', ['$' => 'dollar']));
327+
$this->assertSame('500-dollar-bill', Str::slug('500$--bill', '-', 'en', ['$' => 'dollar']));
328+
$this->assertSame('500-dollar-bill', Str::slug('500-$--bill', '-', 'en', ['$' => 'dollar']));
329+
$this->assertSame('أحمد-في-المدرسة', Str::slug('أحمد@المدرسة', '-', null, ['@' =>'في']));
323330
}
324331

325332
public function testStrStart()

0 commit comments

Comments
 (0)