Skip to content

NOW MANAGED ON CODEBERG

Prevented mulitple hypens incorrectly in slug

Dan Brown711ba258f116
diff --git a/app/Repos/EntityRepo.php b/app/Repos/EntityRepo.php
index 944c0bcfc..d390f3e99 100644
--- a/app/Repos/EntityRepo.php
+++ b/app/Repos/EntityRepo.php
@@ -553,8 +553,9 @@ class EntityRepo
*/
protected function nameToSlug($name)
{
- $slug = str_replace(' ', '-', mb_strtolower($name));
- $slug = preg_replace('/[\+\/\\\?\@\}\{\.\,\=\[\]\#\&\!\*\'\;\:\$\%]/', '', $slug);
+ $slug = preg_replace('/[\+\/\\\?\@\}\{\.\,\=\[\]\#\&\!\*\'\;\:\$\%]/', '', mb_strtolower($name));
+ $slug = preg_replace('/\s{2,}/', ' ', $slug);
+ $slug = str_replace(' ', '-', $slug);
if ($slug === "") $slug = substr(md5(rand(1, 500)), 0, 5);
return $slug;
}
diff --git a/tests/Entity/EntityTest.php b/tests/Entity/EntityTest.php
index 3f23475a0..a43f65b5e 100644
--- a/tests/Entity/EntityTest.php
+++ b/tests/Entity/EntityTest.php
@@ -11,7 +11,6 @@ class EntityTest extends BrowserKitTest
public function test_entity_creation()
{
-
// Test Creation
$book = $this->bookCreation();
$chapter = $this->chapterCreation($book);
@@ -268,4 +267,14 @@ class EntityTest extends BrowserKitTest
}
+ public function test_slug_format()
+ {
+ $entityRepo = app(EntityRepo::class);
+ $book = $entityRepo->createFromInput('book', [
+ 'name' => 'PartA / PartB / PartC'
+ ]);
+
+ $this->assertEquals('parta-partb-partc', $book->slug);
+ }
+
}