diff --git a/Tests/HtmlSanitizerAllTest.php b/Tests/HtmlSanitizerAllTest.php index a0a1511..90436ca 100644 --- a/Tests/HtmlSanitizerAllTest.php +++ b/Tests/HtmlSanitizerAllTest.php @@ -309,6 +309,12 @@ public static function provideSanitizeBody() 'Lorem ipsum ', ], + // Processing instructions + [ + 'Lorem ipsumfoo', + 'Lorem ipsumfoo', + ], + // Normal tags [ 'Lorem ipsum', diff --git a/Visitor/DomVisitor.php b/Visitor/DomVisitor.php index 4c2eba0..8cda8cf 100644 --- a/Visitor/DomVisitor.php +++ b/Visitor/DomVisitor.php @@ -134,9 +134,10 @@ private function visitChildren(\DOMNode $domNode, Cursor $cursor): void if ('#text' === $child->nodeName) { // Add text directly for performance $cursor->node->addChild(new TextNode($cursor->node, $child->nodeValue)); - } elseif (!$child instanceof \DOMText) { + } elseif (!$child instanceof \DOMText && !$child instanceof \DOMProcessingInstruction) { // Otherwise continue the visit recursively // Ignore comments for security reasons (interpreted differently by browsers) + // Ignore processing instructions (treated as comments) $this->visitNode($child, $cursor); } }