<?php namespace BookStack\Entities;
+use Illuminate\Support\Str;
+
class SlugGenerator
{
*/
protected function formatNameAsSlug(string $name): string
{
- $slug = preg_replace('/[\+\/\\\?\@\}\{\.\,\=\[\]\#\&\!\*\'\;\:\$\%]/', '', mb_strtolower($name));
- $slug = preg_replace('/\s{2,}/', ' ', $slug);
- $slug = str_replace(' ', '-', $slug);
+ $slug = Str::slug($name);
if ($slug === "") {
$slug = substr(md5(rand(1, 500)), 0, 5);
}
->seeInElement('#recently-updated-pages', $page->name);
}
- public function test_slug_multi_byte_lower_casing()
+ public function test_slug_multi_byte_url_safe()
{
$book = $this->newBook([
- 'name' => 'Ð\9aÐ\9dÐ\98Ð\93Ð\90'
+ 'name' => 'инÑ\84оÑ\80маÑ\86иÑ\8f'
]);
- $this->assertEquals('книга', $book->slug);
- }
+ $this->assertEquals('informatsiya', $book->slug);
+ $book = $this->newBook([
+ 'name' => '¿Qué?'
+ ]);
+
+ $this->assertEquals('que', $book->slug);
+ }
public function test_slug_format()
{