Skip to content

Commit 4879004

Browse files
committed
Workaround a second libxml bug
1 parent 1270135 commit 4879004

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

ext/dom/document.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,8 +1076,9 @@ static void php_dom_transfer_document_ref(xmlNodePtr node, php_libxml_ref_obj *n
10761076
}
10771077
}
10781078

1079-
/* Workaround for bug that was fixed in https://github.com/GNOME/libxml2/commit/4bc3ebf3eaba352fbbce2ef70ad00a3c7752478a */
1080-
#if LIBXML_VERSION < 21000
1079+
/* Workaround for bug that was fixed in https://github.com/GNOME/libxml2/commit/4bc3ebf3eaba352fbbce2ef70ad00a3c7752478a
1080+
* and https://github.com/GNOME/libxml2/commit/bc7ab5a2e61e4b36accf6803c5b0e245c11154b1 */
1081+
#if LIBXML_VERSION < 21300
10811082
static xmlChar *libxml_copy_dicted_string(xmlDictPtr src_dict, xmlDictPtr dst_dict, xmlChar *str)
10821083
{
10831084
if (str == NULL) {
@@ -1104,18 +1105,23 @@ static void libxml_fixup_name_and_content(xmlDocPtr src_doc, xmlDocPtr dst_doc,
11041105
}
11051106
}
11061107

1107-
static void libxml_fixup_name_and_content_element(xmlDocPtr src_doc, xmlDocPtr dst_doc, xmlNodePtr node)
1108+
static void libxml_fixup_name_and_content_outer(xmlDocPtr src_doc, xmlDocPtr dst_doc, xmlNodePtr node)
11081109
{
11091110
libxml_fixup_name_and_content(src_doc, dst_doc, node);
1110-
for (xmlAttrPtr attr = node->properties; attr != NULL; attr = attr->next) {
1111-
libxml_fixup_name_and_content(src_doc, dst_doc, (xmlNodePtr) attr);
1112-
for (xmlNodePtr attr_child = attr->children; attr_child != NULL; attr_child = attr_child->next) {
1113-
libxml_fixup_name_and_content(src_doc, dst_doc, attr_child);
1111+
1112+
if (node->type == XML_ELEMENT_NODE) {
1113+
for (xmlAttrPtr attr = node->properties; attr != NULL; attr = attr->next) {
1114+
libxml_fixup_name_and_content(src_doc, dst_doc, (xmlNodePtr) attr);
1115+
for (xmlNodePtr attr_child = attr->children; attr_child != NULL; attr_child = attr_child->next) {
1116+
libxml_fixup_name_and_content(src_doc, dst_doc, attr_child);
1117+
}
11141118
}
11151119
}
11161120

1117-
for (xmlNodePtr child = node->children; child != NULL; child = child->next) {
1118-
libxml_fixup_name_and_content_element(src_doc, dst_doc, child);
1121+
if (node->type == XML_ELEMENT_NODE || node->type == XML_ATTRIBUTE_NODE) {
1122+
for (xmlNodePtr child = node->children; child != NULL; child = child->next) {
1123+
libxml_fixup_name_and_content_outer(src_doc, dst_doc, child);
1124+
}
11191125
}
11201126
}
11211127
#endif
@@ -1135,9 +1141,11 @@ bool php_dom_adopt_node(xmlNodePtr nodep, dom_object *dom_object_new_document, x
11351141
return false;
11361142
}
11371143

1138-
#if LIBXML_VERSION < 21000
1144+
#if LIBXML_VERSION < 21300
11391145
/* Must be first before transferring the ref to ensure the old document dictionary stays alive. */
1140-
libxml_fixup_name_and_content_element(old_doc, new_document, nodep);
1146+
if (LIBXML_VERSION < 21000 || nodep->type == XML_ATTRIBUTE_NODE) {
1147+
libxml_fixup_name_and_content_outer(old_doc, new_document, nodep);
1148+
}
11411149
#endif
11421150

11431151
php_dom_transfer_document_ref(nodep, dom_object_new_document->document);

0 commit comments

Comments
 (0)