[icinga-checkins] icinga.org: icingaweb2/master: Url: Build full urlString instead of path if username is set

git at icinga.org git at icinga.org
Thu Oct 20 09:31:15 CEST 2016


Module: icingaweb2
Branch: master
Commit: 3b6b0b8d4b92acff29d3d9d68471a68db56fd3a6
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=3b6b0b8d4b92acff29d3d9d68471a68db56fd3a6

Author: Noah Hilverling <noah.hilverling at netways.de>
Date:   Tue Oct 18 16:19:24 2016 +0200

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 3bc9756..4898864 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()) {
-            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();
-        }
+        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;
+            return $urlString . '/' . $path;
+        } else {
+            return $basePath . ($basePath !== '/' && $path ? '/' : '') . $path;
+        }
     }
 
     /**



More information about the icinga-checkins mailing list