@@ -1076,8 +1076,9 @@ static void php_dom_transfer_document_ref(xmlNodePtr node, php_libxml_ref_obj *n
1076
1076
}
1077
1077
}
1078
1078
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
1081
1082
static xmlChar * libxml_copy_dicted_string (xmlDictPtr src_dict , xmlDictPtr dst_dict , xmlChar * str )
1082
1083
{
1083
1084
if (str == NULL ) {
@@ -1104,18 +1105,23 @@ static void libxml_fixup_name_and_content(xmlDocPtr src_doc, xmlDocPtr dst_doc,
1104
1105
}
1105
1106
}
1106
1107
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 )
1108
1109
{
1109
1110
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
+ }
1114
1118
}
1115
1119
}
1116
1120
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
+ }
1119
1125
}
1120
1126
}
1121
1127
#endif
@@ -1135,9 +1141,11 @@ bool php_dom_adopt_node(xmlNodePtr nodep, dom_object *dom_object_new_document, x
1135
1141
return false;
1136
1142
}
1137
1143
1138
- #if LIBXML_VERSION < 21000
1144
+ #if LIBXML_VERSION < 21300
1139
1145
/* 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
+ }
1141
1149
#endif
1142
1150
1143
1151
php_dom_transfer_document_ref (nodep , dom_object_new_document -> document );
0 commit comments