Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions library/HTMLPurifier/Lexer/DOMLex.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ protected function createStartNode($node, &$tokens, $collect, $config)
} elseif ($node->nodeType === XML_CDATA_SECTION_NODE) {
// undo libxml's special treatment of <script> and <style> tags
$last = end($tokens);
$data = $node->data;
$data = $node->data ?? "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use of null coalesce operator should be reflected in min PHP version required in composer.json (e.g.: "php": ">=7.0"), otherwise the library will be broken on older installations.

// (note $node->tagname is already normalized)
if ($last instanceof HTMLPurifier_Token_Start && ($last->name == 'script' || $last->name == 'style')) {
$new_data = trim($data);
Expand All @@ -213,7 +213,7 @@ protected function createStartNode($node, &$tokens, $collect, $config)
// this is code is only invoked for comments in script/style in versions
// of libxml pre-2.6.28 (regular comments, of course, are still
// handled regularly)
$tokens[] = $this->factory->createComment($node->data);
$tokens[] = $this->factory->createComment($node->data ?? null);
return false;
} elseif ($node->nodeType !== XML_ELEMENT_NODE) {
// not-well tested: there may be other nodes we have to grab
Expand Down Expand Up @@ -264,6 +264,7 @@ protected function transformAttrToAssoc($node_map)
}
$array = array();
foreach ($node_map as $attr) {
if (!isset($attr->name)) continue;
$array[$attr->name] = $attr->value;
}
return $array;
Expand Down