From 5541a721947c86db806f0a9149a7573db391f79c Mon Sep 17 00:00:00 2001 From: Aden Fraser Date: Fri, 26 Aug 2016 14:52:35 +0100 Subject: [PATCH] Strips protocol from defined Route Group Domains --- src/Illuminate/Routing/Route.php | 2 +- tests/Routing/RoutingUrlGeneratorTest.php | 29 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Routing/Route.php b/src/Illuminate/Routing/Route.php index 7d40afa48858..997ecab93d79 100755 --- a/src/Illuminate/Routing/Route.php +++ b/src/Illuminate/Routing/Route.php @@ -820,7 +820,7 @@ public function secure() */ public function domain() { - return isset($this->action['domain']) ? $this->action['domain'] : null; + return isset($this->action['domain']) ? str_replace(['http://', 'https://'], '', $this->action['domain']) : null; } /** diff --git a/tests/Routing/RoutingUrlGeneratorTest.php b/tests/Routing/RoutingUrlGeneratorTest.php index 4a5432f55e81..1950eb4fdf6e 100755 --- a/tests/Routing/RoutingUrlGeneratorTest.php +++ b/tests/Routing/RoutingUrlGeneratorTest.php @@ -292,6 +292,35 @@ public function testRoutesWithDomainsAndPorts() $this->assertEquals('http://sub.taylor.com:8080/foo/bar/otwell', $url->route('bar', ['taylor', 'otwell'])); } + public function testRoutesWithDomainsStripsProtocols() + { + /* + * http:// Route + */ + $url = new UrlGenerator( + $routes = new RouteCollection, + $request = Request::create('http://www.foo.com/') + ); + + $route = new Route(['GET'], 'foo/bar', ['as' => 'foo', 'domain' => 'http://sub.foo.com']); + $routes->add($route); + + $this->assertEquals('http://sub.foo.com/foo/bar', $url->route('foo')); + + /* + * https:// Route + */ + $url = new UrlGenerator( + $routes = new RouteCollection, + $request = Request::create('https://www.foo.com/') + ); + + $route = new Route(['GET'], 'foo/bar', ['as' => 'foo', 'domain' => 'https://sub.foo.com']); + $routes->add($route); + + $this->assertEquals('https://sub.foo.com/foo/bar', $url->route('foo')); + } + public function testHttpsRoutesWithDomains() { $url = new UrlGenerator(