mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
Prevented mulitple hypens incorrectly in slug
Added test to check slug format. Fixes #589
This commit is contained in:
parent
df4d4f30f1
commit
711ba258f1
@ -553,8 +553,9 @@ class EntityRepo
|
|||||||
*/
|
*/
|
||||||
protected function nameToSlug($name)
|
protected function nameToSlug($name)
|
||||||
{
|
{
|
||||||
$slug = str_replace(' ', '-', mb_strtolower($name));
|
$slug = preg_replace('/[\+\/\\\?\@\}\{\.\,\=\[\]\#\&\!\*\'\;\:\$\%]/', '', mb_strtolower($name));
|
||||||
$slug = preg_replace('/[\+\/\\\?\@\}\{\.\,\=\[\]\#\&\!\*\'\;\:\$\%]/', '', $slug);
|
$slug = preg_replace('/\s{2,}/', ' ', $slug);
|
||||||
|
$slug = str_replace(' ', '-', $slug);
|
||||||
if ($slug === "") $slug = substr(md5(rand(1, 500)), 0, 5);
|
if ($slug === "") $slug = substr(md5(rand(1, 500)), 0, 5);
|
||||||
return $slug;
|
return $slug;
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ class EntityTest extends BrowserKitTest
|
|||||||
|
|
||||||
public function test_entity_creation()
|
public function test_entity_creation()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Test Creation
|
// Test Creation
|
||||||
$book = $this->bookCreation();
|
$book = $this->bookCreation();
|
||||||
$chapter = $this->chapterCreation($book);
|
$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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user