diff --git a/ext/dom/node.c b/ext/dom/node.c index a469ce28f77b5..3a6596f8e2e64 100644 --- a/ext/dom/node.c +++ b/ext/dom/node.c @@ -1129,6 +1129,9 @@ PHP_METHOD(DOMNode, removeChild) while (children) { if (children == child) { + if ((child->properties != NULL) && (child->doc != NULL) && child->properties->atype == XML_ATTRIBUTE_ID) { + xmlRemoveID(child->doc, child->properties); + } xmlUnlinkNode(child); DOM_RET_OBJ(child, &ret, intern); return; @@ -1678,7 +1681,7 @@ static void dom_canonicalization(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ buf = xmlAllocOutputBuffer(NULL); } - if (buf != NULL) { + if (buf != NULL) { ret = xmlC14NDocSaveTo(docp, nodeset, exclusive, inclusive_ns_prefixes, with_comments, buf); } @@ -1693,9 +1696,9 @@ static void dom_canonicalization(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ xmlXPathFreeContext(ctxp); } - if (buf == NULL || ret < 0) { - RETVAL_FALSE; - } else { + if (buf == NULL || ret < 0) { + RETVAL_FALSE; + } else { if (mode == 0) { #ifdef LIBXML2_NEW_BUFFER ret = xmlOutputBufferGetSize(buf); @@ -1712,7 +1715,7 @@ static void dom_canonicalization(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ RETVAL_EMPTY_STRING(); } } - } + } if (buf) { int bytes; diff --git a/ext/dom/tests/removeChild_permanently.phpt b/ext/dom/tests/removeChild_permanently.phpt new file mode 100644 index 0000000000000..108d0c23adb65 --- /dev/null +++ b/ext/dom/tests/removeChild_permanently.phpt @@ -0,0 +1,128 @@ +--TEST-- +DOMDocument::removeChild: The node that cannot be removed permanently +--SKIPIF-- + +--FILE-- +createElement('html'); +$dom->appendChild($root); + +$el1 = $dom->createElement('p1'); +$el1->setAttribute('id', 'foo'); +$el1->setIdAttribute('id', true); + +$root->appendChild($el1); + +$el2 = $dom->createElement('p2'); +$el2->setAttribute('id', 'bar'); +$el2->setIdAttribute('id', true); + +$root->appendChild($el2); + +var_dump($dom->getElementById('foo')); +$root->removeChild($dom->getElementById('foo')); +var_dump($dom->getElementById('bar')); +var_dump($dom->getElementById('foo')); +echo $dom->saveXML(); +?> +--EXPECTF-- +object(DOMElement)#%d (%d) { + ["tagName"]=> + string(2) "p1" + ["schemaTypeInfo"]=> + NULL + ["firstElementChild"]=> + NULL + ["lastElementChild"]=> + NULL + ["childElementCount"]=> + int(0) + ["previousElementSibling"]=> + NULL + ["nextElementSibling"]=> + string(22) "(object value omitted)" + ["nodeName"]=> + string(2) "p1" + ["nodeValue"]=> + string(0) "" + ["nodeType"]=> + int(1) + ["parentNode"]=> + string(22) "(object value omitted)" + ["childNodes"]=> + string(22) "(object value omitted)" + ["firstChild"]=> + NULL + ["lastChild"]=> + NULL + ["previousSibling"]=> + NULL + ["nextSibling"]=> + string(22) "(object value omitted)" + ["attributes"]=> + string(22) "(object value omitted)" + ["ownerDocument"]=> + string(22) "(object value omitted)" + ["namespaceURI"]=> + NULL + ["prefix"]=> + string(0) "" + ["localName"]=> + string(2) "p1" + ["baseURI"]=> + NULL + ["textContent"]=> + string(0) "" +} +object(DOMElement)#%d (%d) { + ["tagName"]=> + string(2) "p2" + ["schemaTypeInfo"]=> + NULL + ["firstElementChild"]=> + NULL + ["lastElementChild"]=> + NULL + ["childElementCount"]=> + int(0) + ["previousElementSibling"]=> + NULL + ["nextElementSibling"]=> + NULL + ["nodeName"]=> + string(2) "p2" + ["nodeValue"]=> + string(0) "" + ["nodeType"]=> + int(1) + ["parentNode"]=> + string(22) "(object value omitted)" + ["childNodes"]=> + string(22) "(object value omitted)" + ["firstChild"]=> + NULL + ["lastChild"]=> + NULL + ["previousSibling"]=> + NULL + ["nextSibling"]=> + NULL + ["attributes"]=> + string(22) "(object value omitted)" + ["ownerDocument"]=> + string(22) "(object value omitted)" + ["namespaceURI"]=> + NULL + ["prefix"]=> + string(0) "" + ["localName"]=> + string(2) "p2" + ["baseURI"]=> + NULL + ["textContent"]=> + string(0) "" +} +NULL + +