]> BookStack Code Mirror - bookstack/commitdiff
Merge branch 'master' of github.com:BookStackApp/BookStack
authorDan Brown <redacted>
Sat, 27 Jun 2020 16:19:05 +0000 (17:19 +0100)
committerDan Brown <redacted>
Sat, 27 Jun 2020 16:19:05 +0000 (17:19 +0100)
app/Entities/SlugGenerator.php
tests/Entity/EntityTest.php

index 459a5264a4228148426f7a1174f96da09a32847e..e8bc556abefa102153b64953a6dc76c89784e206 100644 (file)
@@ -1,5 +1,7 @@
 <?php namespace BookStack\Entities;
 
+use Illuminate\Support\Str;
+
 class SlugGenerator
 {
 
@@ -32,9 +34,7 @@ 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);
         }
index d7e4ec61c741f8b0e0822ba1307d7130ce8923c8..de1e025ade6a1e832cad59834f0c0774abf8ad1e 100644 (file)
@@ -273,15 +273,20 @@ class EntityTest extends BrowserKitTest
             ->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()
     {