From 659c1a65bc63482812d716c96988c58009672997 Mon Sep 17 00:00:00 2001 From: jperras Date: Sat, 25 Jul 2009 14:21:34 -0400 Subject: [PATCH 1/3] Modified Inflector::slug to not drop multibyte characters. Fixes #6104. --- cake/libs/inflector.php | 3 ++- cake/tests/cases/libs/inflector.test.php | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cake/libs/inflector.php b/cake/libs/inflector.php index 47fdc3979..b9fcf9502 100644 --- a/cake/libs/inflector.php +++ b/cake/libs/inflector.php @@ -447,10 +447,11 @@ class Inflector extends Object { '/Ü/' => 'Ue', '/Ö/' => 'Oe', '/ß/' => 'ss', - '/[^\w\s]/' => ' ', + '/[^\w\s\p{Ll}\p{Lm}\p{Lo}\p{Lt}\p{Lu}\p{Nd}]/mu' => ' ', '/\\s+/' => $replacement, sprintf('/^[%s]+|[%s]+$/', $quotedReplacement, $quotedReplacement) => '', ); + $map = array_merge($default, $map); return preg_replace(array_keys($map), array_values($map), $string); } diff --git a/cake/tests/cases/libs/inflector.test.php b/cake/tests/cases/libs/inflector.test.php index 0cfc171c9..235dc346d 100644 --- a/cake/tests/cases/libs/inflector.test.php +++ b/cake/tests/cases/libs/inflector.test.php @@ -200,6 +200,10 @@ class InflectorTest extends CakeTestCase { $result = Inflector::slug('#this melts your face1#2#3', '-'); $expected = 'this-melts-your-face1-2-3'; $this->assertEqual($result, $expected); + + $result = Inflector::slug('controller/action/りんご/1'); + $expected = 'controller_action_りんご_1'; + $this->assertEqual($result, $expected); } /** * testInflectorSlugWithMap method From 54d157727623774282ecf2aefe16d47193d71a6f Mon Sep 17 00:00:00 2001 From: jperras Date: Sat, 25 Jul 2009 15:10:21 -0400 Subject: [PATCH 2/3] Adding tests for Inflector::slug with non-latin characters & removing redundant element in preg_replace map. --- cake/libs/inflector.php | 2 +- cake/tests/cases/libs/inflector.test.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cake/libs/inflector.php b/cake/libs/inflector.php index b9fcf9502..c7df92ad9 100644 --- a/cake/libs/inflector.php +++ b/cake/libs/inflector.php @@ -447,7 +447,7 @@ class Inflector extends Object { '/Ü/' => 'Ue', '/Ö/' => 'Oe', '/ß/' => 'ss', - '/[^\w\s\p{Ll}\p{Lm}\p{Lo}\p{Lt}\p{Lu}\p{Nd}]/mu' => ' ', + '/[^\s\p{Ll}\p{Lm}\p{Lo}\p{Lt}\p{Lu}\p{Nd}]/mu' => ' ', '/\\s+/' => $replacement, sprintf('/^[%s]+|[%s]+$/', $quotedReplacement, $quotedReplacement) => '', ); diff --git a/cake/tests/cases/libs/inflector.test.php b/cake/tests/cases/libs/inflector.test.php index 235dc346d..76c2debfd 100644 --- a/cake/tests/cases/libs/inflector.test.php +++ b/cake/tests/cases/libs/inflector.test.php @@ -204,6 +204,14 @@ class InflectorTest extends CakeTestCase { $result = Inflector::slug('controller/action/りんご/1'); $expected = 'controller_action_りんご_1'; $this->assertEqual($result, $expected); + + $result = Inflector::slug('の話が出たので大丈夫かなあと'); + $expected = 'の話が出たので大丈夫かなあと'; + $this->assertEqual($result, $expected); + + $result = Inflector::slug('posts/view/한국어/page:1/sort:asc'); + $expected = 'posts_view_한국어_page_1_sort_asc'; + $this->assertEqual($result, $expected); } /** * testInflectorSlugWithMap method From 6fd0bfc96f43afb622cb7a603b3f251bb5a12a9d Mon Sep 17 00:00:00 2001 From: jperras Date: Sat, 25 Jul 2009 15:11:52 -0400 Subject: [PATCH 3/3] Adding integration test of CacheHelper with newly modified Inflector::slug, on caching actions with non-latin characters in route. --- .../cases/libs/view/helpers/cache.test.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cake/tests/cases/libs/view/helpers/cache.test.php b/cake/tests/cases/libs/view/helpers/cache.test.php index 907146e24..6fa6028f4 100644 --- a/cake/tests/cases/libs/view/helpers/cache.test.php +++ b/cake/tests/cases/libs/view/helpers/cache.test.php @@ -140,6 +140,26 @@ class CacheHelperTest extends CakeTestCase { @unlink($filename); } /** + * test cache parsing with non-latin characters in current route + * + * @access public + * @return void + */ + function testCacheNonLatinCharactersInRoute() { + $this->Controller->cache_parsing(); + $this->Controller->cacheAction = 21600; + $this->Controller->here = '/posts/view/風街ろまん'; + $this->Controller->action = 'view'; + + $View = new View($this->Controller); + $result = $View->render('index'); + + $filename = CACHE . 'views' . DS . 'posts_view_風街ろまん.php'; + $this->assertTrue(file_exists($filename)); + + @unlink($filename); + } +/** * Test cache parsing with cake:nocache tags in view file. * * @access public