diff --git a/Classes/Report/SiteHandlingStatus.php b/Classes/Report/SiteHandlingStatus.php index 84fd95d98b..d22e05db9a 100644 --- a/Classes/Report/SiteHandlingStatus.php +++ b/Classes/Report/SiteHandlingStatus.php @@ -181,13 +181,19 @@ protected function fetchInvalidPartsOfUri(UriInterface $uri): string /* @var UrlHelper $solrUriHelper */ $solrUriHelper = GeneralUtility::makeInstance(UrlHelper::class, $uri); try { - $solrUriHelper->getScheme(); + $scheme = $solrUriHelper->getScheme(); + if (empty($scheme) ) { + $invalidParts .= 'scheme'; + } } catch (\TypeError $error) { $invalidParts .= 'scheme'; } try { - $solrUriHelper->getHost(); + $host = $solrUriHelper->getHost(); + if (empty($host)) { + $invalidParts .= ', host'; + } } catch (\TypeError $error) { $invalidParts .= ', host'; } diff --git a/Classes/System/Url/UrlHelper.php b/Classes/System/Url/UrlHelper.php index 6ace8e1217..a1f37dd75e 100644 --- a/Classes/System/Url/UrlHelper.php +++ b/Classes/System/Url/UrlHelper.php @@ -103,7 +103,7 @@ public function setHost(string $host) */ public function getHost(): string { - return $this->getUrlPart('host'); + return $this->getUrlPart('host') ?? ''; } /** @@ -121,7 +121,7 @@ public function setPort(string $port) */ public function getPort(): string { - return $this->getUrlPart('port'); + return $this->getUrlPart('port') ?? ''; } /** @@ -139,7 +139,7 @@ public function setScheme(string $scheme) */ public function getScheme(): string { - return $this->getUrlPart('scheme'); + return $this->getUrlPart('scheme') ?? ''; } /** @@ -157,7 +157,7 @@ public function setPath($path) */ public function getPath(): string { - return $this->getUrlPart('path'); + return $this->getUrlPart('path') ?? ''; } /** diff --git a/Tests/Unit/System/Url/UrlHelperTest.php b/Tests/Unit/System/Url/UrlHelperTest.php index 44c97d20ed..13023ad388 100644 --- a/Tests/Unit/System/Url/UrlHelperTest.php +++ b/Tests/Unit/System/Url/UrlHelperTest.php @@ -161,4 +161,40 @@ public function testGetUnmodifiedUrl($uri) $urlHelper = new UrlHelper($uri); $this->assertSame($uri, $urlHelper->getUrl(), 'Could not get unmodified url'); } + + /** + * @test + */ + public function ifNoSchemeIsGivenGetSchemeReturnsAnEmptyString(): void + { + $urlHelper = new UrlHelper('www.google.de'); + $this->assertSame('', $urlHelper->getScheme()); + } + + /** + * @test + */ + public function ifNoPathIsGivenGetPathReturnsAnEmptyString(): void + { + $urlHelper = new UrlHelper('https://www.google.de'); + $this->assertSame('', $urlHelper->getPath()); + } + + /** + * @test + */ + public function ifNoPortIsGivenGetPortReturnsAnEmptyString(): void + { + $urlHelper = new UrlHelper('https://www.google.de'); + $this->assertSame('', $urlHelper->getPort()); + } + + /** + * @test + */ + public function ifNoHostIsGivenGetHostReturnsAnEmptyString(): void + { + $urlHelper = new UrlHelper('/my/path/to/a/site'); + $this->assertSame('', $urlHelper->getHost()); + } } \ No newline at end of file