URLs without a seperate label could end up being empty
authorAlexander Ebert <ebert@woltlab.com>
Tue, 2 Jan 2018 14:48:16 +0000 (15:48 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 2 Jan 2018 14:48:16 +0000 (15:48 +0100)
wcfsetup/install/files/lib/system/html/metacode/converter/UrlMetacodeConverter.class.php

index c8cf5682d5919d8a7854413668abcbffd6806ced..5d1f195fce11a1b146aeb7614822b9600f50af9a 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\system\html\metacode\converter;
+use wcf\util\StringUtil;
 
 /**
  * Converts url bbcode into `<a>`.
@@ -22,6 +23,26 @@ class UrlMetacodeConverter extends AbstractMetacodeConverter {
                        $href = $fragment->textContent;
                }
                
+               // check if the link is empty, use the href value instead
+               $useHrefAsValue = false;
+               if ($fragment->childNodes->length === 0) {
+                       $useHrefAsValue = true;
+               }
+               else if ($fragment->childNodes->length === 1) {
+                       $node = $fragment->childNodes->item(0);
+                       if ($node->nodeType === XML_TEXT_NODE && StringUtil::trim($node->textContent) === '') {
+                               $useHrefAsValue = true;
+                       }
+               }
+               
+               if ($useHrefAsValue) {
+                       if ($fragment->childNodes->length === 1) {
+                               $fragment->removeChild($fragment->childNodes->item(0));
+                       }
+                       
+                       $fragment->appendChild($fragment->ownerDocument->createTextNode($href));
+               }
+               
                $element->setAttribute('href', $href);
                $element->appendChild($fragment);