Ensure the URL's authority is fully visible when truncating link values
authorTim Düsterhus <duesterhus@woltlab.com>
Wed, 6 Sep 2023 14:30:33 +0000 (16:30 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 6 Sep 2023 14:30:33 +0000 (16:30 +0200)
wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeA.class.php

index 04893e63c8e2a24ecba98c87efb3306e7542cae4..d730db850a8ad49ab23829126011e5c94c3ec4a1 100644 (file)
@@ -54,8 +54,26 @@ class HtmlOutputNodeA extends AbstractHtmlOutputNode
                     }
 
                     $newValue = $value;
-                    if (\mb_strlen($value) > 60) {
-                        $newValue = \mb_substr($value, 0, 30) . StringUtil::HELLIP . \mb_substr($value, -25);
+                    if (\mb_strlen($newValue) > 60) {
+                        $uri = new Uri($newValue);
+                        $schemeHost = Uri::composeComponents(
+                            $uri->getScheme(),
+                            $uri->getAuthority(),
+                            '',
+                            null,
+                            null,
+                        );
+                        $pathQueryFragment = Uri::composeComponents(
+                            null,
+                            null,
+                            $uri->getPath(),
+                            $uri->getQuery(),
+                            $uri->getFragment(),
+                        );
+                        if (\mb_strlen($pathQueryFragment) > 35) {
+                            $pathQueryFragment = \mb_substr($pathQueryFragment, 0, 15) . StringUtil::HELLIP . \mb_substr($pathQueryFragment, -15);
+                        }
+                        $newValue = $schemeHost . $pathQueryFragment;
                     }
 
                     $element->appendChild(