From aaf6a44a2ce1db1b3ed0f46d64d2e4bf92dc8986 Mon Sep 17 00:00:00 2001 From: Austin Collier Date: Sat, 27 Jan 2024 19:57:04 -0700 Subject: [PATCH] fixed bug with root alias --- flight/net/Route.php | 4 +++- tests/RouterTest.php | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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');