diff --git a/flight/net/Route.php b/flight/net/Route.php index 27a4e70..886fa13 100644 --- a/flight/net/Route.php +++ b/flight/net/Route.php @@ -192,7 +192,9 @@ class Route // catches potential optional parameter $url = str_replace('(/', '/', $url); // trim any trailing slashes - $url = rtrim($url, '/'); + if($url !== '/') { + $url = rtrim($url, '/'); + } return $url; } diff --git a/tests/RouterTest.php b/tests/RouterTest.php index 1f0d33a..6580bf1 100644 --- a/tests/RouterTest.php +++ b/tests/RouterTest.php @@ -533,6 +533,13 @@ class RouterTest extends TestCase $this->assertTrue($result); } + public function testGetRootUrlByAlias() + { + $this->router->map('/', [$this, 'ok'], false, 'path1'); + $url = $this->router->getUrlByAlias('path1'); + $this->assertEquals('/', $url); + } + public function testGetUrlByAliasNoMatches() { $this->router->map('/path1', [$this, 'ok'], false, 'path1');