Permalink
Browse files

fixed utf-8 pattern in router option

  • Loading branch information...
1 parent c1551d9 commit d5283af818b59c5d96355d6e42bbd77e1322d8cb @zoghal zoghal committed Dec 2, 2012
Showing with 25 additions and 1 deletion.
  1. +1 −1 lib/Cake/Routing/Route/CakeRoute.php
  2. +24 −0 lib/Cake/Test/Case/Routing/Route/CakeRouteTest.php
@@ -182,7 +182,7 @@ public function parse($url) {
if (!$this->compiled()) {
$this->compile();
}
- if (!preg_match($this->_compiledRoute, $url, $route)) {
+ if (!preg_match($this->_compiledRoute, urldecode($url), $route)) {
return false;
}
foreach ($this->defaults as $key => $val) {
@@ -880,4 +880,28 @@ public function testParseTrailingUTF8() {
$this->assertEquals($expected, $result);
}
+
+/**
+ * test that utf-8 patterns work for :section
+ *
+ * @return void
+ */
+ public function testUTF8PatternOnSection() {
+ $route = new CakeRoute(
+ '/:section',
+ array('plugin' => 'blogs', 'controller' => 'posts' , 'action' => 'index' ),
+ array(
+ 'persist' => array('section'),
+ 'section' => 'آموزش|weblog'
+ )
+ );
+
+ $result = $route->parse('/%D8%A2%D9%85%D9%88%D8%B2%D8%B4');
+ $expected = array('section' => 'آموزش', 'plugin' => 'blogs', 'controller' => 'posts', 'action' => 'index', 'pass' => array(), 'named' => array());
+ $this->assertEquals($expected, $result);
+
+ $result = $route->parse('/weblog');
+ $expected = array('section' => 'weblog', 'plugin' => 'blogs', 'controller' => 'posts', 'action' => 'index', 'pass' => array(), 'named' => array());
+ $this->assertEquals($expected, $result);
+ }
}

3 comments on commit d5283af

This modification breaks routes that include a urlencoded '/' in a parameter.

Owner

markstory replied Mar 20, 2014

That is unfortunate, I would think utf8 characters are more likely to be found in path segments over encoded / 's.

Contributor

zoghal replied Mar 20, 2014

@lemon-lime For more reviews, please tell me an example of a url that failed

Please sign in to comment.