Skip to content

Commit 6fbdf69

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix #81433: DOMElement::setIdAttribute() called twice may remove ID
2 parents e766378 + 424c265 commit 6fbdf69

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2021, PHP 8.0.12
44

5+
- DOM:
6+
. Fixed bug #81433 (DOMElement::setIdAttribute() called twice may remove ID).
7+
(Viktor Volkov)
58

69
23 Sep 2021, PHP 8.0.11
710

ext/dom/element.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,11 +1024,9 @@ static void php_set_attribute_id(xmlAttrPtr attrp, zend_bool is_id) /* {{{ */
10241024
xmlAddID(NULL, attrp->doc, id_val, attrp);
10251025
xmlFree(id_val);
10261026
}
1027-
} else {
1028-
if (attrp->atype == XML_ATTRIBUTE_ID) {
1029-
xmlRemoveID(attrp->doc, attrp);
1030-
attrp->atype = 0;
1031-
}
1027+
} else if (is_id == 0 && attrp->atype == XML_ATTRIBUTE_ID) {
1028+
xmlRemoveID(attrp->doc, attrp);
1029+
attrp->atype = 0;
10321030
}
10331031
}
10341032
/* }}} */

ext/dom/tests/bug81433.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Bug #81433 (DOMElement::setIdAttribute(attr, true) called twice removes ID)
3+
--SKIPIF--
4+
<?php
5+
require_once('skipif.inc');
6+
?>
7+
--FILE--
8+
<?php
9+
$dom = new DOMDocument('1.0', 'utf-8');
10+
11+
$element = $dom->createElement('test', 'root');
12+
13+
$dom->appendChild($element);
14+
15+
$element->setAttribute("id", 123);
16+
$element->setIdAttribute("id", true);
17+
18+
$node = $element->getAttributeNode("id");
19+
var_dump($node->isId());
20+
21+
$element->setIdAttribute("id", true);
22+
var_dump($node->isId());
23+
?>
24+
--EXPECT--
25+
bool(true)
26+
bool(true)

0 commit comments

Comments
 (0)