From f6f90822d658c7156b2abd569eda89bbeb811b16 Mon Sep 17 00:00:00 2001 From: Noah Hilverling Date: Tue, 18 Oct 2016 12:25:11 +0200 Subject: [PATCH] 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 ba77b3b03..28290e2f7 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: