Skip to content
Permalink
Browse files

Fix match() not enabling multibyte patterns.

When matching parameter values in reverse routing we should use unicode
patterns to make unicode life easier.

Refs #12314
  • Loading branch information...
markstory committed Jul 3, 2018
1 parent d997562 commit 3a9051792c010b45f070332c0c1ebaa332f847e0
Showing with 13 additions and 26 deletions.
  1. +1 −1 src/Routing/Route/Route.php
  2. +12 −25 tests/TestCase/Routing/Route/RouteTest.php
@@ -742,7 +742,7 @@ public function match(array $url, array $context = [])
// check patterns for routed params
if (!empty($this->options)) {
foreach ($this->options as $key => $pattern) {
if (isset($url[$key]) && !preg_match('#^' . $pattern . '$#', $url[$key])) {
if (isset($url[$key]) && !preg_match('#^' . $pattern . '$#u', $url[$key])) {
return false;
}
}
@@ -505,7 +505,7 @@ public function testRouteCompilingWithParamPatterns()
*
* @return void
*/
public function testRouteCompilingWithUnicodePatterns()
public function testCompileWithUnicodePatterns()
{
$route = new Route(
'/test/:slug',
@@ -1050,36 +1050,23 @@ public function testMatchWithPatterns()
}
/**
* Test that match() pulls out extra arguments as query string params.
* Test that match() with multibyte pattern
*
* @return void
*/
public function testMatchExtractQueryStringArgs()
public function testMatchWithMultibytePattern()
{
$route = new Route('/:controller/:action/*');
$result = $route->match([
'controller' => 'posts',
'action' => 'index',
'page' => 1
]);
$this->assertEquals('/posts/index?page=1', $result);
$result = $route->match([
'controller' => 'posts',
'action' => 'index',
'page' => 0
]);
$this->assertEquals('/posts/index?page=0', $result);
$route = new Route(
'/articles/:action/:id',
['controller' => 'Articles'],
['multibytePattern' => true, 'id' => '\pL+']
);
$result = $route->match([
'controller' => 'posts',
'action' => 'index',
1,
'page' => 1,
'dir' => 'desc',
'order' => 'title'
'controller' => 'Articles',
'action' => 'view',
'id' => "\xC4\x81"
]);
$this->assertEquals('/posts/index/1?page=1&dir=desc&order=title', $result);
$this->assertEquals("/articles/view/\xC4\x81", $result);
}
/**

0 comments on commit 3a90517

Please sign in to comment.
You can’t perform that action at this time.