[icinga-checkins] icinga.org: icingaweb2/master: Url: Set basePath correctly in methods fromRequest and fromPath

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


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

Author: Noah Hilverling <noah.hilverling at netways.de>
Date:   Tue Oct 18 12:25:11 2016 +0200

Url: Set basePath correctly in methods fromRequest and fromPath

refs #12133

---

 library/Icinga/Web/Url.php |   18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/library/Icinga/Web/Url.php b/library/Icinga/Web/Url.php
index ba77b3b..28290e2 100644
--- a/library/Icinga/Web/Url.php
+++ b/library/Icinga/Web/Url.php
@@ -133,7 +133,7 @@ class Url
             $urlParams->set($k, $v);
         }
         $url->setParams($urlParams);
-        $url->setBaseUrl($request->getBaseUrl());
+        $url->setBasePath($request->getBaseUrl());
         return $url;
     }
 
@@ -191,17 +191,27 @@ class Url
             || (isset($urlParts['port']) && $urlParts['port'] != $request->getServer('SERVER_PORT')))
         ) {
             $urlObject->setIsExternal();
-        } else {
-            $urlObject->setBasePath($request->getBaseUrl());
         }
 
         if (isset($urlParts['path'])) {
             $urlPath = $urlParts['path'];
             if ($urlPath && $urlPath[0] === '/') {
-                $urlPath = substr($urlPath, 1);
+                if ($urlObject->isExternal()) {
+                    $urlPath = substr($urlPath, 1);
+                } else {
+                    $requestBaseUrl = $request->getBaseUrl();
+                    if ($requestBaseUrl && $requestBaseUrl !== '/' && strpos($urlPath, $requestBaseUrl) === 0) {
+                        $urlPath = substr($urlPath, strlen($requestBaseUrl) + 1);
+                        $urlObject->setBasePath($requestBaseUrl);
+                    }
+                }
+            } elseif (!$urlObject->isExternal()) {
+                $urlObject->setBasePath($request->getBaseUrl());
             }
 
             $urlObject->setPath($urlPath);
+        } elseif (!$urlObject->isExternal()) {
+            $urlObject->setBasePath($request->getBaseUrl());
         }
 
         // TODO: This has been used by former filter implementation, remove it:



More information about the icinga-checkins mailing list