From 550b85fdbb76580817db98535dd016ccb6cb1b2d Mon Sep 17 00:00:00 2001 From: the_undefined Date: Sun, 18 May 2008 05:03:12 +0000 Subject: [PATCH] Improved Inflector::slug, closes #4678 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6920 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/inflector.php | 1 + cake/tests/cases/libs/inflector.test.php | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/cake/libs/inflector.php b/cake/libs/inflector.php index c894bc931..8164eb20f 100644 --- a/cake/libs/inflector.php +++ b/cake/libs/inflector.php @@ -438,6 +438,7 @@ class Inflector extends Object { '/ß/' => 'ss', '/[^\w\s]/' => ' ', '/\\s+/' => $replacement, + String::insert('/^[:replacement]+|[:replacement]+$/', array('replacement' => preg_quote($replacement, '/'))) => '', ); $string = preg_replace(array_keys($map), array_values($map), $string); return $string; diff --git a/cake/tests/cases/libs/inflector.test.php b/cake/tests/cases/libs/inflector.test.php index 84b751aa9..12c7c309b 100644 --- a/cake/tests/cases/libs/inflector.test.php +++ b/cake/tests/cases/libs/inflector.test.php @@ -147,6 +147,18 @@ class InflectorTest extends UnitTestCase { $result = Inflector::slug('La langue française est un attribut de souveraineté en France', '-'); $expected = 'La-langue-francaise-est-un-attribut-de-souverainete-en-France'; $this->assertEqual($result, $expected); + + $result = Inflector::slug('!@$#exciting stuff! - what !@-# was that?', '-'); + $expected = 'exciting-stuff-what-was-that'; + $this->assertEqual($result, $expected); + + $result = Inflector::slug('20% of profits went to me!', '-'); + $expected = '20-of-profits-went-to-me'; + $this->assertEqual($result, $expected); + + $result = Inflector::slug('#this melts your face1#2#3', '-'); + $expected = 'this-melts-your-face1-2-3'; + $this->assertEqual($result, $expected); } function testVariableNaming() {