From: Alexander Ebert Date: Sun, 25 Sep 2016 22:47:01 +0000 (+0200) Subject: Discarding invalid tables w/o content X-Git-Tag: 3.0.0_Beta_2~135 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=aac8493fda973dd49a283a70b5d9ecbb72a412ee;p=GitHub%2FWoltLab%2FWCF.git Discarding invalid tables w/o content --- diff --git a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeTable.class.php b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeTable.class.php new file mode 100644 index 0000000000..ae0fdd4bad --- /dev/null +++ b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeTable.class.php @@ -0,0 +1,55 @@ +` and removes invalid tables. This action can + * be done safely, because completely messed up tables have already + * been crippled by HTMLPurifier. + * + * @author Alexander Ebert + * @copyright 2001-2016 WoltLab GmbH + * @license GNU Lesser General Public License + * @package WoltLabSuite\Core\System\Html\Input\Node + * @since 3.0 + */ +class HtmlInputNodeWoltlabTable extends AbstractHtmlInputNode { + /** + * @inheritDoc + */ + protected $tagName = 'table'; + + /** + * @inheritDoc + */ + public function isAllowed(AbstractHtmlNodeProcessor $htmlNodeProcessor) { + return []; + } + + /** + * @inheritDoc + */ + public function process(array $elements, AbstractHtmlNodeProcessor $htmlNodeProcessor) { + /** @var \DOMElement $element */ + foreach ($elements as $element) { + $trs = []; + /** @var \DOMElement $tr */ + foreach ($element->getElementsByTagName('tr') as $tr) { + $trs[] = $tr; + } + + // check if each `` has at least one `` + foreach ($trs as $tr) { + if ($tr->getElementsByTagName('td')->length === 0) { + DOMUtil::removeNode($tr); + } + } + + if ($element->getElementsByTagName('tr')->length === 0) { + // garbage table, remove + DOMUtil::removeNode($element); + } + } + } +}