Skip to content

Commit e4f22d8

Browse files
committed
revert slug change
1 parent 4856c42 commit e4f22d8

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/Illuminate/Support/Str.php

+16-2
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,23 @@ public static function singular($value)
551551
*/
552552
public static function slug($title, $separator = '-', $language = 'en')
553553
{
554-
$language = $language ?? '';
554+
$title = $language ? static::ascii($title, $language) : $title;
555555

556-
return ASCII::to_slugify((string) $title, $separator, $language, [], true);
556+
// Convert all dashes/underscores into separator
557+
$flip = $separator === '-' ? '_' : '-';
558+
559+
$title = preg_replace('!['.preg_quote($flip).']+!u', $separator, $title);
560+
561+
// Replace @ with the word 'at'
562+
$title = str_replace('@', $separator.'at'.$separator, $title);
563+
564+
// Remove all characters that are not the separator, letters, numbers, or whitespace.
565+
$title = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', static::lower($title));
566+
567+
// Replace all separator characters and whitespace by a single separator
568+
$title = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $title);
569+
570+
return trim($title, $separator);
557571
}
558572

559573
/**

tests/Support/SupportStrTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public function testSlug()
200200
$this->assertSame('hello-world', Str::slug('hello_world'));
201201
$this->assertSame('hello_world', Str::slug('hello_world', '_'));
202202
$this->assertSame('user-at-host', Str::slug('user@host'));
203-
$this->assertSame('slam-dnya', Str::slug('سلام دنیا', '-', null));
203+
// $this->assertSame('slam-dnya', Str::slug('سلام دنیا', '-', null));
204204
}
205205

206206
public function testStrStart()

tests/Support/SupportStringableTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public function testSlug()
229229
$this->assertSame('hello-world', (string) $this->stringable('hello_world')->slug());
230230
$this->assertSame('hello_world', (string) $this->stringable('hello_world')->slug('_'));
231231
$this->assertSame('user-at-host', (string) $this->stringable('user@host')->slug());
232-
$this->assertSame('slam-dnya', (string) $this->stringable('سلام دنیا')->slug('-', null));
232+
// $this->assertSame('slam-dnya', (string) $this->stringable('سلام دنیا')->slug('-', null));
233233
}
234234

235235
public function testStart()

0 commit comments

Comments
 (0)