From 3b6b0b8d4b92acff29d3d9d68471a68db56fd3a6 Mon Sep 17 00:00:00 2001 From: Noah Hilverling Date: Tue, 18 Oct 2016 16:19:24 +0200 Subject: [PATCH] Url: Build full urlString instead of path if username is set refs #12133 --- library/Icinga/Web/Url.php | 39 ++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/library/Icinga/Web/Url.php b/library/Icinga/Web/Url.php index 3bc975695..4898864ad 100644 --- a/library/Icinga/Web/Url.php +++ b/library/Icinga/Web/Url.php @@ -586,28 +586,31 @@ class Url } $basePath = $this->getBasePath(); - if (!$basePath) { + if (! $basePath) { $basePath = '/'; } - if (!$this->isExternal()) { + + if ($this->getUsername() || $this->isExternal()) { + $urlString = ''; + if ($this->getScheme()) { + $urlString .= $this->getScheme() . '://'; + } + if ($this->getPassword()) { + $urlString .= $this->getUsername() . ':' . $this->getPassword() . '@'; + } elseif ($this->getUsername()) { + $urlString .= $this->getUsername() . '@'; + } + if ($this->getHost()) { + $urlString .= $this->getHost(); + } + if ($this->getPort()) { + $urlString .= ':' . $this->getPort(); + } + + return $urlString . '/' . $path; + } else { return $basePath . ($basePath !== '/' && $path ? '/' : '') . $path; } - - $urlString = ''; - if ($this->getScheme()) { - $urlString = $urlString . $this->getScheme() . '://'; - } - if ($this->getUsername() && $this->getPassword()) { - $urlString = $urlString . $this->getUsername() . ':' . $this->getPassword() . "@"; - } - if ($this->getHost()) { - $urlString = $urlString . $this->getHost(); - } - if ($this->getPort()) { - $urlString = $urlString . $this->getPort(); - } - - return $urlString . '/' . $path; } /**