Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make route patterns allow multibyte sub-patterns.
This allows route parameter matching patterns to contain multibyte
expressions which is useful for restricting parameters in non-ascii
character sets.

Refs #8332
  • Loading branch information
markstory committed Feb 25, 2016
1 parent 262ec6e commit c3ff7e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Routing/Route/Route.php
Expand Up @@ -201,7 +201,7 @@ protected function _writeRoute()
}
krsort($routeParams);
$parsed = str_replace(array_keys($routeParams), array_values($routeParams), $parsed);
$this->_compiledRoute = '#^' . $parsed . '[/]*$#';
$this->_compiledRoute = '#^' . $parsed . '[/]*$#u';
$this->keys = $names;

// Remove defaults that are also keys. They can cause match failures
Expand Down
13 changes: 13 additions & 0 deletions tests/TestCase/Routing/Route/RouteTest.php
Expand Up @@ -207,6 +207,19 @@ public function testRouteCompilingWithParamPatterns()
$this->assertEquals(['url_title', 'id'], $route->keys);
}

public function testRouteCompilingWithUnicodePatterns()
{
$route = new Route(
'/test/:slug',
['controller' => 'Pages', 'action' => 'display'],
['pass' => ['slug'], 'slug' => '[A-zА-я\-\ ]+']
);
$result = $route->compile();
$this->assertRegExp($result, '/test/abcDEF');
$this->assertRegExp($result, '/test/bla-blan-тест');
$this->assertNotRegExp($result, '/test/9999');
}

/**
* test more complex route compiling & parsing with mid route greedy stars
* and optional routing parameters
Expand Down

0 comments on commit c3ff7e9

Please sign in to comment.