diff --git a/src/UrlGenerator.php b/src/UrlGenerator.php index 0a1080a..e7a5677 100644 --- a/src/UrlGenerator.php +++ b/src/UrlGenerator.php @@ -53,7 +53,7 @@ public function to($path, $extra = [], $secure = null) $url = parent::to($path, $extra, $secure); - if (Str::endsWith($path, '/')) { + if (Str::endsWith($path, '/') && $path !== '/') { return $url.'/'; } diff --git a/tests/UrlGeneratorTest.php b/tests/UrlGeneratorTest.php index 43f1c10..4dba2e7 100644 --- a/tests/UrlGeneratorTest.php +++ b/tests/UrlGeneratorTest.php @@ -16,6 +16,8 @@ public function testBasicGeneration() Request::create('http://www.example.com/') ); + $this->assertEquals('http://www.example.com/', $urlGenerator->to('/')); + $this->assertEquals('http://www.example.com/foo/', $urlGenerator->to('foo/')); $this->assertEquals('http://www.example.com/foo/bar', $urlGenerator->to('foo/bar')); $this->assertEquals('http://www.example.com/foo/bar/', $urlGenerator->to('foo/bar/')); $this->assertEquals('http://www.example.com/foo/bar/', $urlGenerator->to('foo/bar//'));