From 404909ffaa37f4c756817c0b1e459efee62b90a6 Mon Sep 17 00:00:00 2001 From: "Daniel St. Jules" Date: Mon, 17 Feb 2014 11:21:06 -0500 Subject: [PATCH] Fixes #19: Handle consecutive invalid chars in slugify --- src/Stringy.php | 1 + tests/CommonTest.php | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/Stringy.php b/src/Stringy.php index a34f3b5..3122c6c 100644 --- a/src/Stringy.php +++ b/src/Stringy.php @@ -713,6 +713,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess $stringy->toAscii()); $stringy->str = $stringy->collapseWhitespace()->str; $stringy->str = str_replace(' ', $replacement, strtolower($stringy)); + $stringy->str = preg_replace("/[$replacement]+/u", $replacement, $stringy); return $stringy; } diff --git a/tests/CommonTest.php b/tests/CommonTest.php index 21399ea..d8b482e 100644 --- a/tests/CommonTest.php +++ b/tests/CommonTest.php @@ -333,6 +333,8 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase { return array( array('foo-bar', ' foo bar '), + array('foo-bar', 'foo -.-"-...bar'), + array('another-foo-bar', 'another..& foo -.-"-...bar'), array('foo-dbar', " Foo d'Bar "), array('a-string-with-dashes', 'A string-with-dashes'), array('using-strings-like-foo-bar', 'Using strings like fòô bàř'),