From 406be00436c2e2d609ccdde42e4ed57088980de4 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 10 Jan 2019 12:28:16 +0200 Subject: [PATCH 1/2] Add a failing test for routing URLs containing Cyrillic letters. --- tests/RouterTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/RouterTest.php b/tests/RouterTest.php index 3f38aa1..8b20853 100644 --- a/tests/RouterTest.php +++ b/tests/RouterTest.php @@ -263,4 +263,16 @@ class RouterTest extends PHPUnit_Framework_TestCase $this->check('404'); } + + + // Passing URL parameters matched with regular expression for a URL containing Cyrillic letters: + function testRegExParametersCyrillic(){ + $this->router->map('/категория/@name:[абвгдеёжзийклмнопрстуфхцчшщъыьэюя]+', function($name){ + echo $name; + }); + $this->request->url = urlencode('/категория/цветя'); + + $this->check('цветя'); + } + } From 0daa3f81b584bf50e9f75b15c7f65364570eb7c5 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 10 Jan 2019 12:29:23 +0200 Subject: [PATCH 2/2] Allow cyrillic letters in the routes, by matching the result of urldecode over the URL . --- flight/net/Router.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/flight/net/Router.php b/flight/net/Router.php index 6a2f73b..47c81b9 100644 --- a/flight/net/Router.php +++ b/flight/net/Router.php @@ -78,8 +78,9 @@ class Router { * @return Route|bool Matching route or false if no match */ public function route(Request $request) { + $url_decoded = urldecode( $request->url ); while ($route = $this->current()) { - if ($route !== false && $route->matchMethod($request->method) && $route->matchUrl($request->url, $this->case_sensitive)) { + if ($route !== false && $route->matchMethod($request->method) && $route->matchUrl($url_decoded, $this->case_sensitive)) { return $route; } $this->next();