From 88ccaaa010d2fbb5b3f3e172c58339d019b29bf5 Mon Sep 17 00:00:00 2001 From: Viktor Date: Fri, 10 Sep 2021 10:14:18 +0300 Subject: [PATCH 1/3] fix(php_set_attribute_id): fix incorrect ID removal, when is_id == 1 --- ext/dom/element.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ext/dom/element.c b/ext/dom/element.c index 51aba0e155175..274b11cfe1bdd 100644 --- a/ext/dom/element.c +++ b/ext/dom/element.c @@ -1157,11 +1157,9 @@ static void php_set_attribute_id(xmlAttrPtr attrp, zend_bool is_id) /* {{{ */ xmlAddID(NULL, attrp->doc, id_val, attrp); xmlFree(id_val); } - } else { - if (attrp->atype == XML_ATTRIBUTE_ID) { - xmlRemoveID(attrp->doc, attrp); - attrp->atype = 0; - } + } else if (is_id == 0 && attrp->atype == XML_ATTRIBUTE_ID) { + xmlRemoveID(attrp->doc, attrp); + attrp->atype = 0; } } /* }}} */ From 60c8d9800339d9f9fb4f6e6f3d31a3e63bca18d0 Mon Sep 17 00:00:00 2001 From: Viktor Date: Mon, 13 Sep 2021 09:04:50 +0300 Subject: [PATCH 2/3] test: add regression test for DOMElement::setIdAttribute --- ext/dom/tests/bug81433.phpt | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 ext/dom/tests/bug81433.phpt diff --git a/ext/dom/tests/bug81433.phpt b/ext/dom/tests/bug81433.phpt new file mode 100644 index 0000000000000..5e1e0046a30cd --- /dev/null +++ b/ext/dom/tests/bug81433.phpt @@ -0,0 +1,31 @@ +--TEST-- +Bug #81433 (DOMElement::setIdAttribute(attr, true) called twice removes ID) +--SKIPIF-- += 20912) die('skip For libxml2 < 2.9.12 only'); +?> +--FILE-- +createElement('test', 'root'); + +$dom->appendChild($element); + +$element->setAttribute("id", 123); +$element->setIdAttribute("id", true); + +$node = $element->getAttributeNode("id"); +var_dump($node->isId()); + +$element->setIdAttribute("id", true); +var_dump($node->isId()); +?> +--CLEAN-- + +--EXPECT-- +bool(true) +bool(true) From fb54a3253d80218b0f9181b2ecd62029c21e8c0e Mon Sep 17 00:00:00 2001 From: Viktor Date: Mon, 13 Sep 2021 11:41:46 +0300 Subject: [PATCH 3/3] test: improve regression test of DOMElement::setIdAttribute --- ext/dom/tests/bug81433.phpt | 9 --------- 1 file changed, 9 deletions(-) diff --git a/ext/dom/tests/bug81433.phpt b/ext/dom/tests/bug81433.phpt index 5e1e0046a30cd..fb378695b16ed 100644 --- a/ext/dom/tests/bug81433.phpt +++ b/ext/dom/tests/bug81433.phpt @@ -1,10 +1,5 @@ --TEST-- Bug #81433 (DOMElement::setIdAttribute(attr, true) called twice removes ID) ---SKIPIF-- -= 20912) die('skip For libxml2 < 2.9.12 only'); -?> --FILE-- isId()); $element->setIdAttribute("id", true); var_dump($node->isId()); ?> ---CLEAN-- - --EXPECT-- bool(true) bool(true)