Skip to content

Commit 3a90517

Browse files
committed
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
1 parent d997562 commit 3a90517

File tree

2 files changed

+13
-26
lines changed

2 files changed

+13
-26
lines changed

src/Routing/Route/Route.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ public function match(array $url, array $context = [])
742742
// check patterns for routed params
743743
if (!empty($this->options)) {
744744
foreach ($this->options as $key => $pattern) {
745-
if (isset($url[$key]) && !preg_match('#^' . $pattern . '$#', $url[$key])) {
745+
if (isset($url[$key]) && !preg_match('#^' . $pattern . '$#u', $url[$key])) {
746746
return false;
747747
}
748748
}

tests/TestCase/Routing/Route/RouteTest.php

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ public function testRouteCompilingWithParamPatterns()
505505
*
506506
* @return void
507507
*/
508-
public function testRouteCompilingWithUnicodePatterns()
508+
public function testCompileWithUnicodePatterns()
509509
{
510510
$route = new Route(
511511
'/test/:slug',
@@ -1050,36 +1050,23 @@ public function testMatchWithPatterns()
10501050
}
10511051

10521052
/**
1053-
* Test that match() pulls out extra arguments as query string params.
1053+
* Test that match() with multibyte pattern
10541054
*
10551055
* @return void
10561056
*/
1057-
public function testMatchExtractQueryStringArgs()
1057+
public function testMatchWithMultibytePattern()
10581058
{
1059-
$route = new Route('/:controller/:action/*');
1060-
$result = $route->match([
1061-
'controller' => 'posts',
1062-
'action' => 'index',
1063-
'page' => 1
1064-
]);
1065-
$this->assertEquals('/posts/index?page=1', $result);
1066-
1067-
$result = $route->match([
1068-
'controller' => 'posts',
1069-
'action' => 'index',
1070-
'page' => 0
1071-
]);
1072-
$this->assertEquals('/posts/index?page=0', $result);
1073-
1059+
$route = new Route(
1060+
'/articles/:action/:id',
1061+
['controller' => 'Articles'],
1062+
['multibytePattern' => true, 'id' => '\pL+']
1063+
);
10741064
$result = $route->match([
1075-
'controller' => 'posts',
1076-
'action' => 'index',
1077-
1,
1078-
'page' => 1,
1079-
'dir' => 'desc',
1080-
'order' => 'title'
1065+
'controller' => 'Articles',
1066+
'action' => 'view',
1067+
'id' => "\xC4\x81"
10811068
]);
1082-
$this->assertEquals('/posts/index/1?page=1&dir=desc&order=title', $result);
1069+
$this->assertEquals("/articles/view/\xC4\x81", $result);
10831070
}
10841071

10851072
/**

0 commit comments

Comments
 (0)