diff options
author | git-marijus <mario@mariovavti.com> | 2018-03-23 10:25:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-23 10:25:58 +0100 |
commit | e2b9162a30f60ba74038c4aa999d31d5e9338d7c (patch) | |
tree | dce716a2a6955b0b43d6176daa75517982a65541 /vendor/ezyang/htmlpurifier/library/HTMLPurifier/Lexer/DOMLex.php | |
parent | eec4d9b5ad2ad3fbc4d5c5651fcccdc81b248af9 (diff) | |
parent | c80837a9e6a1d5049a03fbb608b2b650c1b0f92d (diff) | |
download | volse-hubzilla-e2b9162a30f60ba74038c4aa999d31d5e9338d7c.tar.gz volse-hubzilla-e2b9162a30f60ba74038c4aa999d31d5e9338d7c.tar.bz2 volse-hubzilla-e2b9162a30f60ba74038c4aa999d31d5e9338d7c.zip |
Merge pull request #1010 from dawnbreak/dev
:arrow_up: Update libraries.
Diffstat (limited to 'vendor/ezyang/htmlpurifier/library/HTMLPurifier/Lexer/DOMLex.php')
-rw-r--r-- | vendor/ezyang/htmlpurifier/library/HTMLPurifier/Lexer/DOMLex.php | 57 |
1 files changed, 47 insertions, 10 deletions
diff --git a/vendor/ezyang/htmlpurifier/library/HTMLPurifier/Lexer/DOMLex.php b/vendor/ezyang/htmlpurifier/library/HTMLPurifier/Lexer/DOMLex.php index 22ab5820c..6238a99e3 100644 --- a/vendor/ezyang/htmlpurifier/library/HTMLPurifier/Lexer/DOMLex.php +++ b/vendor/ezyang/htmlpurifier/library/HTMLPurifier/Lexer/DOMLex.php @@ -127,6 +127,41 @@ class HTMLPurifier_Lexer_DOMLex extends HTMLPurifier_Lexer } /** + * Portably retrieve the tag name of a node; deals with older versions + * of libxml like 2.7.6 + * @param DOMNode $node + */ + protected function getTagName($node) + { + if (property_exists($node, 'tagName')) { + return $node->tagName; + } else if (property_exists($node, 'nodeName')) { + return $node->nodeName; + } else if (property_exists($node, 'localName')) { + return $node->localName; + } + return null; + } + + /** + * Portably retrieve the data of a node; deals with older versions + * of libxml like 2.7.6 + * @param DOMNode $node + */ + protected function getData($node) + { + if (property_exists($node, 'data')) { + return $node->data; + } else if (property_exists($node, 'nodeValue')) { + return $node->nodeValue; + } else if (property_exists($node, 'textContent')) { + return $node->textContent; + } + return null; + } + + + /** * @param DOMNode $node DOMNode to be tokenized. * @param HTMLPurifier_Token[] $tokens Array-list of already tokenized tokens. * @param bool $collect Says whether or start and close are collected, set to @@ -141,7 +176,10 @@ class HTMLPurifier_Lexer_DOMLex extends HTMLPurifier_Lexer // but we're not getting the character reference nodes because // those should have been preprocessed if ($node->nodeType === XML_TEXT_NODE) { - $tokens[] = $this->factory->createText($node->data); + $data = $this->getData($node); // Handle variable data property + if ($data !== null) { + $tokens[] = $this->factory->createText($data); + } return false; } elseif ($node->nodeType === XML_CDATA_SECTION_NODE) { // undo libxml's special treatment of <script> and <style> tags @@ -171,21 +209,20 @@ class HTMLPurifier_Lexer_DOMLex extends HTMLPurifier_Lexer // not-well tested: there may be other nodes we have to grab return false; } - $attr = $node->hasAttributes() ? $this->transformAttrToAssoc($node->attributes) : array(); - + $tag_name = $this->getTagName($node); // Handle variable tagName property + if (empty($tag_name)) { + return (bool) $node->childNodes->length; + } // We still have to make sure that the element actually IS empty if (!$node->childNodes->length) { if ($collect) { - $tokens[] = $this->factory->createEmpty($node->tagName, $attr); + $tokens[] = $this->factory->createEmpty($tag_name, $attr); } return false; } else { if ($collect) { - $tokens[] = $this->factory->createStart( - $tag_name = $node->tagName, // somehow, it get's dropped - $attr - ); + $tokens[] = $this->factory->createStart($tag_name, $attr); } return true; } @@ -197,10 +234,10 @@ class HTMLPurifier_Lexer_DOMLex extends HTMLPurifier_Lexer */ protected function createEndNode($node, &$tokens) { - $tokens[] = $this->factory->createEnd($node->tagName); + $tag_name = $this->getTagName($node); // Handle variable tagName property + $tokens[] = $this->factory->createEnd($tag_name); } - /** * Converts a DOMNamedNodeMap of DOMAttr objects into an assoc array. * |