diff --git a/src/ServerRequest.php b/src/ServerRequest.php index 7115682c6c257f4c3b6a43a488ae177b1da207f9..486dbc82c24ca88b8a396ff897e84475a9ee7c83 100644 --- a/src/ServerRequest.php +++ b/src/ServerRequest.php @@ -400,7 +400,7 @@ class ServerRequest extends Request implements ServerRequestInterface $base = $this->getBase(); } - return substr($this->getUri()->getPath(), strlen(rtrim($base))); + return substr($this->getUri()->getPath(), strlen(rtrim($base, '/'))); } /** diff --git a/tests/ServerRequestTest.php b/tests/ServerRequestTest.php index 3a8b322eb070e3b04227823628f7e2d9cc94da2b..3e45950251fdba9115ca6e46cb75348463ca141b 100644 --- a/tests/ServerRequestTest.php +++ b/tests/ServerRequestTest.php @@ -548,4 +548,11 @@ class ServerRequestTest extends TestCase self::assertSame('/product/42', $request->getRelativePath()); } + + public function testGetRelativePathFromRoot() + { + $request = new ServerRequest('GET', '/product/42'); + + self::assertSame('/product/42', $request->getRelativePath('/')); + } }