diff --git a/library/Icinga/Web/Url.php b/library/Icinga/Web/Url.php index f4fcba381..7b9af3644 100644 --- a/library/Icinga/Web/Url.php +++ b/library/Icinga/Web/Url.php @@ -179,10 +179,9 @@ class Url } $urlParts = parse_url($url); - if (isset($urlParts['scheme']) && ( - $urlParts['scheme'] !== $request->getScheme() + if ((isset($urlParts['scheme']) && $urlParts['scheme'] !== $request->getScheme()) || (isset($urlParts['host']) && $urlParts['host'] !== $request->getServer('SERVER_NAME')) - || (isset($urlParts['port']) && $urlParts['port'] != $request->getServer('SERVER_PORT'))) + || (isset($urlParts['port']) && $urlParts['port'] != $request->getServer('SERVER_PORT')) ) { $urlObject->setIsExternal(); } diff --git a/test/php/library/Icinga/Web/UrlTest.php b/test/php/library/Icinga/Web/UrlTest.php index cbe8b6bf8..6a6088f2f 100644 --- a/test/php/library/Icinga/Web/UrlTest.php +++ b/test/php/library/Icinga/Web/UrlTest.php @@ -71,6 +71,11 @@ class UrlTest extends BaseTestCase ); } + public function testWhetherProtocolRelativeUrlsAreDetectedAsBeingExternal() + { + $this->assertTrue(Url::fromPath('//testhost/path/to/my/url.html')->isExternal()); + } + public function testWhetherGetAbsoluteUrlReturnsTheGivenUsernameAndPassword() { $url = Url::fromPath('http://testusername:testpassword@testsite.com/path/to/my/url.html');