From bbbfee23d7ecf4f0f80598c2ebeddc4944ea0c50 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sun, 23 Jul 2023 14:59:32 +0200 Subject: [PATCH 1/2] Add test with wrong output --- ...ibuteNodeNS_same_uri_different_prefix.phpt | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 ext/dom/tests/setAttributeNodeNS_same_uri_different_prefix.phpt diff --git a/ext/dom/tests/setAttributeNodeNS_same_uri_different_prefix.phpt b/ext/dom/tests/setAttributeNodeNS_same_uri_different_prefix.phpt new file mode 100644 index 0000000000000..a4531901e1547 --- /dev/null +++ b/ext/dom/tests/setAttributeNodeNS_same_uri_different_prefix.phpt @@ -0,0 +1,38 @@ +--TEST-- +setAttributeNodeNS with same URI but different prefix +--EXTENSIONS-- +dom +--FILE-- +appendChild($doc->createElement('container')); +$attribute = $doc->createAttributeNS('http://php.net/ns1', 'foo:hello'); +$attribute->nodeValue = '1'; +var_dump($doc->documentElement->setAttributeNodeNS($attribute)?->nodeValue); +echo $doc->saveXML(), "\n"; +$attribute = $doc->createAttributeNS('http://php.net/ns1', 'bar:hello'); +$attribute->nodeValue = '2'; +var_dump($doc->documentElement->setAttributeNodeNS($attribute)?->nodeValue); +echo $doc->saveXML(), "\n"; +$attribute = $doc->createAttributeNS('http://php.net/ns1', 'hello'); +$attribute->nodeValue = '3'; +var_dump($doc->documentElement->setAttributeNodeNS($attribute)?->nodeValue); +echo $doc->saveXML(), "\n"; +?> +--EXPECT-- +NULL + + + +NULL + + + +NULL + + From 70394261025e8724eae770a1f9154f07e3de3702 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sun, 23 Jul 2023 15:00:59 +0200 Subject: [PATCH 2/2] Fix incorrect attribute existence check in DOMElement::setAttributeNodeNS() --- ext/dom/element.c | 2 +- .../setAttributeNodeNS_same_uri_different_prefix.phpt | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ext/dom/element.c b/ext/dom/element.c index 44c576a07363f..0a4e0c3ec847f 100644 --- a/ext/dom/element.c +++ b/ext/dom/element.c @@ -862,7 +862,7 @@ PHP_METHOD(DOMElement, setAttributeNodeNS) nsp = attrp->ns; if (nsp != NULL) { - existattrp = xmlHasNsProp(nodep, nsp->href, attrp->name); + existattrp = xmlHasNsProp(nodep, attrp->name, nsp->href); } else { existattrp = xmlHasProp(nodep, attrp->name); } diff --git a/ext/dom/tests/setAttributeNodeNS_same_uri_different_prefix.phpt b/ext/dom/tests/setAttributeNodeNS_same_uri_different_prefix.phpt index a4531901e1547..622b586cea846 100644 --- a/ext/dom/tests/setAttributeNodeNS_same_uri_different_prefix.phpt +++ b/ext/dom/tests/setAttributeNodeNS_same_uri_different_prefix.phpt @@ -27,12 +27,12 @@ echo $doc->saveXML(), "\n"; --EXPECT-- NULL - + -NULL +string(1) "1" - + -NULL +string(1) "2" - +