Fix the default hostname for links without hostnames
authorAlexander Ebert <ebert@woltlab.com>
Mon, 29 Jan 2024 17:37:37 +0000 (18:37 +0100)
committerOlaf Braun <info@braun-development.de>
Thu, 7 Mar 2024 15:36:53 +0000 (16:36 +0100)
See https://www.woltlab.com/community/thread/302070-link-ohne-protokoll-zeigt-auf-localhost/

wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeA.class.php

index 3234761de4acfcbb3278228113ba6d4e5f23a29c..e33f93706c1c82bbaff275af825cc17b000901b0 100644 (file)
@@ -66,6 +66,12 @@ class HtmlOutputNodeA extends AbstractHtmlOutputNode
 
             if ($href->getScheme() !== 'mailto') {
                 if (ApplicationHandler::getInstance()->isInternalURL($href->__toString())) {
+                    if ($href->getHost() === '') {
+                        // `withScheme()` implicitly adds `localhost`
+                        // https://www.woltlab.com/community/thread/302070-link-ohne-protokoll-zeigt-auf-localhost/
+                        $href = $href->withHost(ApplicationHandler::getInstance()->getDomainName());
+                    }
+
                     $href = $href->withScheme(RouteHandler::secureConnection() ? 'https' : 'http');
 
                     $element->setAttribute(