summaryrefslogtreecommitdiff
path: root/ext/domxml/php_domxml.c
diff options
context:
space:
mode:
authorMelvyn Sopacua <msopacua@php.net>2003-09-09 19:43:45 +0000
committerMelvyn Sopacua <msopacua@php.net>2003-09-09 19:43:45 +0000
commitcd8ba5af5baeb5a380bc8a8b8aab1ff800a0e69a (patch)
treea6e13c76d9f61017360929ee626226e14c8d5166 /ext/domxml/php_domxml.c
parentfc787ac20f0a8a78902a2e1676b94b43fcb90659 (diff)
downloadphp-git-cd8ba5af5baeb5a380bc8a8b8aab1ff800a0e69a.tar.gz
Fix #23326: Attributes via append_child not supported
Add testcase
Diffstat (limited to 'ext/domxml/php_domxml.c')
-rw-r--r--ext/domxml/php_domxml.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/ext/domxml/php_domxml.c b/ext/domxml/php_domxml.c
index f6666c0e57..e222d462e5 100644
--- a/ext/domxml/php_domxml.c
+++ b/ext/domxml/php_domxml.c
@@ -2425,11 +2425,6 @@ PHP_FUNCTION(domxml_node_append_child)
DOMXML_GET_OBJ(child, node, le_domxmlnodep);
- if (child->type == XML_ATTRIBUTE_NODE) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't append attribute node");
- RETURN_FALSE;
- }
-
/* XXX:ls */
if (child == parent) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't append node to itself");
@@ -2469,6 +2464,28 @@ PHP_FUNCTION(domxml_node_append_child)
}
}
/* end libxml2 code */
+ else if (child->type == XML_ATTRIBUTE_NODE) {
+ if (parent->properties != NULL) {
+ /* Check if an attribute with the same name exists */
+ xmlAttrPtr foundattrp;
+ if (child->ns == NULL)
+ foundattrp = xmlHasProp(parent, child->name);
+ else
+ foundattrp = xmlHasNsProp(parent, child->name, child->ns->href);
+ if ((foundattrp != NULL) && (foundattrp != (xmlAttrPtr) child)) {
+ xmlUnlinkNode((xmlNodePtr) foundattrp);
+ (void)xmlCopyProp(parent, (xmlAttrPtr) child);
+ /* We're in the dark here, what happened to the parent, let's
+ * assume it's handled properly and return the new(?) parent
+ */
+ new_child = parent;
+ }
+ }
+ /* For all other intents and purposes fall through to the xmlAddChild
+ * call
+ */
+ }
+
if (NULL == new_child) {
new_child = xmlAddChild(parent, child);