Prevented mulitple hypens incorrectly in slug

Added test to check slug format.
Fixes #589
This commit is contained in:
Dan Brown 2017-11-11 16:27:29 +00:00
parent df4d4f30f1
commit 711ba258f1
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
2 changed files with 13 additions and 3 deletions

View File

@ -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;
}

View File

@ -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);
}
}