Page MenuHomePhabricator

D581.id.diff
No OneTemporary

D581.id.diff

diff --git a/tests/StringTest.php b/tests/StringTest.php
--- a/tests/StringTest.php
+++ b/tests/StringTest.php
@@ -14,8 +14,17 @@
public function testSlugSpecialChars() {
$this->assertEquals('a-string-with-special-chars', Strings::slug('a string with spëcìal chàrs'));
- $this->assertEquals('a-string-with-special-chrs', Strings::slug('a string with spëcìal chªrs'));
- $this->assertEquals('a-string-with-special-chrs', Strings::slug('a_string_with spëcìal chªrs'));
+ $this->assertEquals('a-string-with-special-ch-rs', Strings::slug('a string with spëcìal chªrs'));
+ $this->assertEquals('a-string-with-special-ch-rs', Strings::slug('a_string_with spëcìal chªrs'));
+ $this->assertEquals('a-string-with-special-ch-rs', Strings::slug('a_string_with spëcìal ch&rs'));
+ $this->assertEquals('a-string-with-special-ch-rs', Strings::slug('a_string_with spëcìal ch@rs'));
+ $this->assertEquals('a-string-with-special-h-rs', Strings::slug('a_string_with spëcìal ©h@rs'));
+ }
+
+ public function testSlugPunctuation() {
+ $this->assertEquals('category-news', Strings::slug('category:news'));
+ $this->assertEquals('category-news', Strings::slug('category;news'));
+ $this->assertEquals('category-news', Strings::slug('category/news'));
}
public function testSlugUppercase() {
diff --git a/utils/Strings.php b/utils/Strings.php
--- a/utils/Strings.php
+++ b/utils/Strings.php
@@ -35,16 +35,17 @@
}
public static function slug($string) {
- $str = preg_replace(
+
+ $str = strtolower(preg_replace(
+ Array('/[^\p{L}0-9_\-\s]/u', '/[ \-\_ª]+/'),
+ Array('-' /*Remove non-alphanumeric characters*/, '-' /*Remove multiple spaces*/),
+ $string));
+
+ return preg_replace(
/*http://stackoverflow.com/questions/10444885/php-replace-foreign-characters-in-a-string*/
'/&([A-Za-z]{1,2})(acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);/i',
'$1', //Remove accents
- htmlentities($string, ENT_QUOTES, 'UTF-8'));
-
- return strtolower(preg_replace(
- Array('/[^A-Za-z0-9_\-\s]/', '/[ \-\_]+/'),
- Array('' /*Remove non-alphanumeric characters*/, '-' /*Remove multiple spaces*/),
- html_entity_decode($str, ENT_QUOTES, 'UTF-8')));
+ htmlentities($str, ENT_QUOTES, 'UTF-8'));
}
public static function endsWith($haystack, $needle) {

File Metadata

Mime Type
text/plain
Expires
Wed, Apr 14, 4:23 AM (3 w, 6 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5822
Default Alt Text
D581.id.diff (2 KB)

Event Timeline