Skip to content

Commit 6f988ff

Browse files
committed
feature symfony#15 Optimized slugger: trimming dash at the beginning & end and removed doubles dashes (Sebastian Blum)
This PR was merged into the master branch. Discussion ---------- Optimized slugger: trimming dash at the beginning & end and removed doubles dashes Hello, I found the symfony-demo repository and the idea behind is great. also in the symfony best practices, the slugger has 2 problems in my opinion. * several dashes like lorem--ipsum * dashes at the begin or end like -lorem-ipsum- here is my litte pull request. sebastian Commits ------- 5c82409 Optimized slugger: trimming dash at the beginning & end and removed double dashes
2 parents 493e74b + 5c82409 commit 6f988ff

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/AppBundle/Tests/Utils/SluggerTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ public function getSlugs()
4242
return array(
4343
array('Lorem Ipsum' , 'lorem-ipsum'),
4444
array(' Lorem Ipsum ' , 'lorem-ipsum'),
45-
array(' lOrEm iPsUm ' , 'lorem--ipsum'),
45+
array(' lOrEm iPsUm ' , 'lorem-ipsum'),
46+
array('!Lorem Ipsum!' , 'lorem-ipsum'),
47+
array('lorem-ipsum' , 'lorem-ipsum'),
4648
);
4749
}
4850
}

src/AppBundle/Utils/Slugger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ class Slugger
2222
{
2323
public function slugify($string)
2424
{
25-
return preg_replace('/[^a-z0-9]/', '-', strtolower(trim(strip_tags($string))));
25+
return trim(preg_replace('/[^a-z0-9]+/', '-', strtolower(trim(strip_tags($string)))), '-');
2626
}
2727
}

0 commit comments

Comments
 (0)