From 5311f14e5b9e3b066eb797ca622541f0fbfbe40f Mon Sep 17 00:00:00 2001 From: Dustin Wilson Date: Mon, 14 Feb 2022 14:03:56 -0600 Subject: [PATCH] Fixes to attributes in Node::isEqualNode --- lib/Node.php | 8 ++++++-- tests/cases/TestNode.php | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/Node.php b/lib/Node.php index e704905..1b5f416 100644 --- a/lib/Node.php +++ b/lib/Node.php @@ -1061,8 +1061,12 @@ abstract class Node implements \Stringable { # • If A is an element, each attribute in its attribute list has an attribute that # equals an attribute in B’s attribute list. $thisNodeAttributes = $thisNode->attributes; - foreach ($thisNodeAttributes as $key => $attr) { - if (!$this->isEqualInnerNode($attr, $otherAttributes[$key])) { + foreach ($thisNodeAttributes as $attr) { + if (!($otherAttr = $otherNode->getAttributeNodeNS($attr->namespaceURI, $attr->name))) { + return false; + } + + if (!$this->isEqualInnerNode($attr, $otherAttr)) { return false; } } diff --git a/tests/cases/TestNode.php b/tests/cases/TestNode.php index 7894852..01cc113 100644 --- a/tests/cases/TestNode.php +++ b/tests/cases/TestNode.php @@ -378,6 +378,11 @@ class TestNode extends \PHPUnit\Framework\TestCase { $this->assertFalse($html->isEqualNode($html2)); $html->appendChild($body); $this->assertFalse($html->isEqualNode($html2)); + $html = $d->createElement('html'); + $html->setAttribute('id', 'ook'); + $html2 = $d->createElement('html'); + $html2->setAttribute('class', 'ook'); + $this->assertFalse($html->isEqualNode($html2)); // Different text nodes $this->assertFalse($d->createTextNode('ook')->isEqualNode($d->createTextNode('eek')));