diff --git a/NEWS b/NEWS index f97a5fe659d..4a3f865b137 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,9 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 2021, PHP 8.0.12 +- DOM: + . Fixed bug #81433 (DOMElement::setIdAttribute() called twice may remove ID). + (Viktor Volkov) 23 Sep 2021, PHP 8.0.11 diff --git a/ext/dom/element.c b/ext/dom/element.c index 450d694c41d..4835c7fad91 100644 --- a/ext/dom/element.c +++ b/ext/dom/element.c @@ -1024,11 +1024,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; } } /* }}} */ diff --git a/ext/dom/tests/bug81433.phpt b/ext/dom/tests/bug81433.phpt new file mode 100644 index 00000000000..d587fe4de56 --- /dev/null +++ b/ext/dom/tests/bug81433.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #81433 (DOMElement::setIdAttribute(attr, true) called twice removes ID) +--SKIPIF-- + +--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()); +?> +--EXPECT-- +bool(true) +bool(true)