Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5c82409

Browse filesBrowse files
author
Sebastian Blum
committed
Optimized slugger: trimming dash at the beginning & end and removed double dashes
1 parent 8cf500c commit 5c82409
Copy full SHA for 5c82409

File tree

2 files changed

+4
-2
lines changed
Filter options

2 files changed

+4
-2
lines changed

‎src/AppBundle/Tests/Utils/SluggerTest.php

Copy file name to clipboardExpand all lines: src/AppBundle/Tests/Utils/SluggerTest.php
+3-1Lines 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

Copy file name to clipboardExpand all lines: src/AppBundle/Utils/Slugger.php
+1-1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.