Improved Inflector::slug, closes #4678

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6920 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
the_undefined 2008-05-18 05:03:12 +00:00
parent 8313fef72d
commit 550b85fdbb
2 changed files with 13 additions and 0 deletions

View file

@ -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;

View file

@ -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() {