From 13bb2ba08e7c8d7f83b4cccb59e0b92ffafedf38 Mon Sep 17 00:00:00 2001 From: Tom Schlick Date: Thu, 3 May 2018 14:24:40 -0400 Subject: [PATCH 1/3] use getBaseUrl() instead of getBasePath() --- src/Illuminate/Routing/RouteUrlGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Routing/RouteUrlGenerator.php b/src/Illuminate/Routing/RouteUrlGenerator.php index 7eb57eeb0e7a..768681d8ed81 100644 --- a/src/Illuminate/Routing/RouteUrlGenerator.php +++ b/src/Illuminate/Routing/RouteUrlGenerator.php @@ -98,7 +98,7 @@ public function to($route, $parameters = [], $absolute = false) if (! $absolute) { $uri = preg_replace('#^(//|[^/?])+#', '', $uri); - if ($base = $this->request->getBasePath()) { + if ($base = $this->request->getBaseUrl()) { $uri = preg_replace('#^'.$base.'#i', '', $uri); } From 0853b2b314f49b56df34abd0070bb5f1c02b4e4a Mon Sep 17 00:00:00 2001 From: Tom Schlick Date: Thu, 3 May 2018 14:54:23 -0400 Subject: [PATCH 2/3] add tests for request url with filename suffix --- tests/Routing/RoutingUrlGeneratorTest.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/Routing/RoutingUrlGeneratorTest.php b/tests/Routing/RoutingUrlGeneratorTest.php index f96f1f9654c5..9198dfb78bea 100755 --- a/tests/Routing/RoutingUrlGeneratorTest.php +++ b/tests/Routing/RoutingUrlGeneratorTest.php @@ -64,7 +64,7 @@ public function testBasicGenerationWithHostFormatting() $this->assertEquals('/named-route', $url->route('plain', [], false)); } - public function testBasicGenerationWithRequestBasePath() + public function testBasicGenerationWithRequestBaseUrl() { $request = Request::create('http://www.foo.com/subfolder/foo/bar/subfolder/'); @@ -79,7 +79,27 @@ public function testBasicGenerationWithRequestBasePath() $route = new Route(['GET'], 'foo/bar/subfolder', ['as' => 'foobar']); $routes->add($route); + $this->assertEquals('/subfolder', $request->getBaseUrl()); + $this->assertEquals('/foo/bar/subfolder', $url->route('foobar', [], false)); + } + + public function testBasicGenerationWithRequestBaseUrlWithFileSuffix() + { + $request = Request::create('http://www.foo.com/subfolder/index.php'); + + $request->server->set('SCRIPT_FILENAME', '/var/www/laravel-project/public/subfolder/index.php'); + $request->server->set('PHP_SELF', '/subfolder/index.php'); + + $url = new UrlGenerator( + $routes = new RouteCollection, + $request + ); + + $route = new Route(['GET'], 'foo/bar/subfolder', ['as' => 'foobar']); + $routes->add($route); + $this->assertEquals('/subfolder', $request->getBasePath()); + $this->assertEquals('/subfolder/index.php', $request->getBaseUrl()); $this->assertEquals('/foo/bar/subfolder', $url->route('foobar', [], false)); } From 5df8e20aca45fc21272ccb8cbc9bbda157affba7 Mon Sep 17 00:00:00 2001 From: Tom Schlick Date: Thu, 3 May 2018 15:03:38 -0400 Subject: [PATCH 3/3] add test case for files not in a folder --- tests/Routing/RoutingUrlGeneratorTest.php | 24 +++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/Routing/RoutingUrlGeneratorTest.php b/tests/Routing/RoutingUrlGeneratorTest.php index 9198dfb78bea..150f98d7d4cf 100755 --- a/tests/Routing/RoutingUrlGeneratorTest.php +++ b/tests/Routing/RoutingUrlGeneratorTest.php @@ -64,7 +64,7 @@ public function testBasicGenerationWithHostFormatting() $this->assertEquals('/named-route', $url->route('plain', [], false)); } - public function testBasicGenerationWithRequestBaseUrl() + public function testBasicGenerationWithRequestBaseUrlWithSubfolder() { $request = Request::create('http://www.foo.com/subfolder/foo/bar/subfolder/'); @@ -83,7 +83,7 @@ public function testBasicGenerationWithRequestBaseUrl() $this->assertEquals('/foo/bar/subfolder', $url->route('foobar', [], false)); } - public function testBasicGenerationWithRequestBaseUrlWithFileSuffix() + public function testBasicGenerationWithRequestBaseUrlWithSubfolderAndFileSuffix() { $request = Request::create('http://www.foo.com/subfolder/index.php'); @@ -103,6 +103,26 @@ public function testBasicGenerationWithRequestBaseUrlWithFileSuffix() $this->assertEquals('/foo/bar/subfolder', $url->route('foobar', [], false)); } + public function testBasicGenerationWithRequestBaseUrlWithFileSuffix() + { + $request = Request::create('http://www.foo.com/other.php'); + + $request->server->set('SCRIPT_FILENAME', '/var/www/laravel-project/public/other.php'); + $request->server->set('PHP_SELF', '/other.php'); + + $url = new UrlGenerator( + $routes = new RouteCollection, + $request + ); + + $route = new Route(['GET'], 'foo/bar/subfolder', ['as' => 'foobar']); + $routes->add($route); + + $this->assertEquals('', $request->getBasePath()); + $this->assertEquals('/other.php', $request->getBaseUrl()); + $this->assertEquals('/foo/bar/subfolder', $url->route('foobar', [], false)); + } + public function testBasicGenerationWithPathFormatting() { $url = new UrlGenerator(