Skip to content

Commit 9ffa3f9

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix #81433: DOMElement::setIdAttribute() called twice may remove ID
2 parents 9042c7a + 6fbdf69 commit 9ffa3f9

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.1.0RC2
44

5+
- DOM:
6+
. Fixed bug #81433 (DOMElement::setIdAttribute() called twice may remove ID).
7+
(Viktor Volkov)
8+
59
- Shmop:
610
. Fixed bug #81407 (shmop_open won't attach and causes php to crash). (cmb)
711

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

0 commit comments

Comments
 (0)