Skip to content
Permalink
Browse files

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 c3ff7e9e8e61f76bfb49151226996ed34afc3009
Showing with 14 additions and 1 deletion.
  1. +1 −1 src/Routing/Route/Route.php
  2. +13 −0 tests/TestCase/Routing/Route/RouteTest.php
@@ -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
@@ -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

0 comments on commit c3ff7e9

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