Skip to content

Commit

Permalink
Fix match() not enabling multibyte patterns.
Browse files Browse the repository at this point in the history
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 3a90517
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/Routing/Route/Route.php
Expand Up @@ -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;
}
}
Expand Down
37 changes: 12 additions & 25 deletions tests/TestCase/Routing/Route/RouteTest.php
Expand Up @@ -505,7 +505,7 @@ public function testRouteCompilingWithParamPatterns()
*
* @return void
*/
public function testRouteCompilingWithUnicodePatterns()
public function testCompileWithUnicodePatterns()
{
$route = new Route(
'/test/:slug',
Expand Down Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 3a90517

Please sign in to comment.