Merge branch 'PHP-7.4' into PHP-8.0

* PHP-7.4:
  Fix #81433: DOMElement::setIdAttribute() called twice may remove ID
This commit is contained in:
Christoph M. Becker 2021-09-13 12:12:39 +02:00
commit 6fbdf69628
No known key found for this signature in database
GPG key ID: D66C9593118BCCB6
3 changed files with 32 additions and 5 deletions

3
NEWS
View file

@ -2,6 +2,9 @@ PHP NEWS
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 2021, PHP 8.0.12 ?? ??? 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 23 Sep 2021, PHP 8.0.11

View file

@ -1024,11 +1024,9 @@ static void php_set_attribute_id(xmlAttrPtr attrp, zend_bool is_id) /* {{{ */
xmlAddID(NULL, attrp->doc, id_val, attrp); xmlAddID(NULL, attrp->doc, id_val, attrp);
xmlFree(id_val); xmlFree(id_val);
} }
} else { } else if (is_id == 0 && attrp->atype == XML_ATTRIBUTE_ID) {
if (attrp->atype == XML_ATTRIBUTE_ID) { xmlRemoveID(attrp->doc, attrp);
xmlRemoveID(attrp->doc, attrp); attrp->atype = 0;
attrp->atype = 0;
}
} }
} }
/* }}} */ /* }}} */

View file

@ -0,0 +1,26 @@
--TEST--
Bug #81433 (DOMElement::setIdAttribute(attr, true) called twice removes ID)
--SKIPIF--
<?php
require_once('skipif.inc');
?>
--FILE--
<?php
$dom = new DOMDocument('1.0', 'utf-8');
$element = $dom->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)