From 0665219d219659f452ea4dda4d85a9a09de78c75 Mon Sep 17 00:00:00 2001 From: Lukas Geiter Date: Thu, 30 Apr 2015 22:54:54 +0200 Subject: [PATCH] Fix trailing slash --- src/Application.php | 2 +- tests/FullApplicationTest.php | 40 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/Application.php b/src/Application.php index 93dd9acc09d4..eb57b3e54630 100644 --- a/src/Application.php +++ b/src/Application.php @@ -1348,7 +1348,7 @@ public function getPathInfo() { $query = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : ''; - return '/'.ltrim(str_replace('?'.$query, '', $_SERVER['REQUEST_URI']), '/'); + return '/'.trim(str_replace('?'.$query, '', $_SERVER['REQUEST_URI']), '/'); } /** diff --git a/tests/FullApplicationTest.php b/tests/FullApplicationTest.php index 6190a68bc20b..4dd7e3435553 100644 --- a/tests/FullApplicationTest.php +++ b/tests/FullApplicationTest.php @@ -27,6 +27,46 @@ public function testBasicRequest() } + public function testRequestWithoutSymfonyClass() + { + $app = new Application; + + $app->get('/', function () { + return response('Hello World'); + }); + + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_SERVER['REQUEST_URI'] = '/'; + + $response = $app->dispatch(); + + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('Hello World', $response->getContent()); + + unset($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']); + } + + + public function testRequestWithoutSymfonyClassTrailingSlash() + { + $app = new Application; + + $app->get('/foo', function () { + return response('Hello World'); + }); + + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_SERVER['REQUEST_URI'] = '/foo/'; + + $response = $app->dispatch(); + + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('Hello World', $response->getContent()); + + unset($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']); + } + + public function testRequestWithParameters() { $app = new Application;