Skip to content

Commit b2d778c

Browse files
committed
Fix crash when toggleAttribute() is used without a document
1 parent f20edf0 commit b2d778c

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ PHP NEWS
2020
- DOM:
2121
. Fixed bug GH-12870 (Creating an xmlns attribute results in a DOMException).
2222
(nielsdos)
23+
. Fix crash when toggleAttribute() is used without a document. (nielsdos)
2324

2425
- FFI:
2526
. Fixed bug GH-9698 (stream_wrapper_register crashes with FFI\CData).

ext/dom/element.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1554,7 +1554,7 @@ PHP_METHOD(DOMElement, toggleAttribute)
15541554
}
15551555

15561556
/* Step 2 */
1557-
if (thisp->doc->type == XML_HTML_DOCUMENT_NODE && (thisp->ns == NULL || xmlStrEqual(thisp->ns->href, (const xmlChar *) "http://www.w3.org/1999/xhtml"))) {
1557+
if (thisp->doc != NULL && thisp->doc->type == XML_HTML_DOCUMENT_NODE && (thisp->ns == NULL || xmlStrEqual(thisp->ns->href, (const xmlChar *) "http://www.w3.org/1999/xhtml"))) {
15581558
qname_tmp = zend_str_tolower_dup_ex(qname, qname_length);
15591559
if (qname_tmp != NULL) {
15601560
qname = qname_tmp;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
DOMElement::toggleAttribute() without a document
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
$element = new DOMElement("container");
9+
$element->toggleAttribute('foo', true);
10+
11+
$dom = new DOMDocument;
12+
$element = $dom->importNode($element, true);
13+
echo $dom->saveXML($element), "\n";
14+
15+
?>
16+
--EXPECT--
17+
<container foo=""/>

0 commit comments

Comments
 (0)