From 64924af14ec85480fd400cbde495077585fcf5e1 Mon Sep 17 00:00:00 2001 From: Julien Rosset Date: Tue, 15 Nov 2022 18:14:02 +0100 Subject: [PATCH] Fix auto add '/' if URL path is not absolute (now only if host set) --- src/UrlInfo/UrlInfo.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/UrlInfo/UrlInfo.php b/src/UrlInfo/UrlInfo.php index 812b636..0ee8f84 100644 --- a/src/UrlInfo/UrlInfo.php +++ b/src/UrlInfo/UrlInfo.php @@ -123,7 +123,7 @@ class UrlInfo { $url .= ':' . $this->getPort(); } if ($this->hasPath()) { - $url .= ($url === '' || !$this->isPathAbsolute() ? '' : '/') . $this->getPath(); + $url .= ($this->hasHost() && !$this->isPathAbsolute() ? '/' : '') . $this->getPath(); } if ($this->hasArguments()) { $url .= '?' . $this->getArgumentsAsString(); @@ -304,7 +304,7 @@ class UrlInfo { * @return string|null The URL path */ public function getPath (): ?string { - return $this->hasPathParts() ? $this->getPathParts()->join('/') : null; + return $this->hasPathParts() ? preg_replace('#/{2,}#', '/', $this->getPathParts()->join('/')) : null; } /** * The URL path parts