@@ -542,17 +542,32 @@ static zend_always_inline int dom_xml_serialize_text_node(xmlOutputBufferPtr out
542
542
return dom_xml_common_text_serialization (out , (const char * ) text -> content , false);
543
543
}
544
544
545
+ static int dom_xml_serialize_attribute_node_value (xmlOutputBufferPtr out , xmlAttrPtr attr )
546
+ {
547
+ TRY (xmlOutputBufferWriteString (out , (const char * ) attr -> name ));
548
+ TRY (xmlOutputBufferWrite (out , strlen ("=\"" ), "=\"" ));
549
+ for (xmlNodePtr child = attr -> children ; child != NULL ; child = child -> next ) {
550
+ if (child -> type == XML_TEXT_NODE ) {
551
+ if (child -> content != NULL ) {
552
+ TRY (dom_xml_common_text_serialization (out , (const char * ) child -> content , true));
553
+ }
554
+ } else if (child -> type == XML_ENTITY_REF_NODE ) {
555
+ TRY (xmlOutputBufferWrite (out , strlen ("&" ), "&" ));
556
+ TRY (dom_xml_common_text_serialization (out , (const char * ) child -> name , true));
557
+ TRY (xmlOutputBufferWrite (out , strlen (";" ), ";" ));
558
+ }
559
+ }
560
+ return xmlOutputBufferWrite (out , strlen ("\"" ), "\"" );
561
+ }
562
+
545
563
/* Spec says to do nothing, but that's inconsistent/wrong, see https://github.com/w3c/DOM-Parsing/issues/28 */
546
564
static int dom_xml_serialize_attribute_node (xmlOutputBufferPtr out , xmlNodePtr attr )
547
565
{
548
566
if (attr -> ns != NULL && attr -> ns -> prefix != NULL ) {
549
567
TRY (xmlOutputBufferWriteString (out , (const char * ) attr -> ns -> prefix ));
550
568
TRY (xmlOutputBufferWrite (out , strlen (":" ), ":" ));
551
569
}
552
- TRY (xmlOutputBufferWriteString (out , (const char * ) attr -> name ));
553
- TRY (xmlOutputBufferWrite (out , strlen ("=\"" ), "=\"" ));
554
- TRY (dom_xml_common_text_serialization (out , (const char * ) dom_get_attribute_value ((xmlAttrPtr ) attr ), true));
555
- return xmlOutputBufferWrite (out , strlen ("\"" ), "\"" );
570
+ return dom_xml_serialize_attribute_node_value (out , (xmlAttrPtr ) attr );
556
571
}
557
572
558
573
/* https://w3c.github.io/DOM-Parsing/#dfn-xml-serializing-a-comment-node */
@@ -730,10 +745,7 @@ static int dom_xml_serialize_attributes(
730
745
* => N/A */
731
746
732
747
/* 3.9. Append the following strings to result, in the order listed: */
733
- TRY (xmlOutputBufferWriteString (out , (const char * ) attr -> name ));
734
- TRY (xmlOutputBufferWrite (out , strlen ("=\"" ), "=\"" ));
735
- TRY (dom_xml_common_text_serialization (out , (const char * ) dom_get_attribute_value (attr ), true));
736
- TRY (xmlOutputBufferWrite (out , strlen ("\"" ), "\"" ));
748
+ dom_xml_serialize_attribute_node_value (out , attr );
737
749
}
738
750
739
751
/* 4. Return the value of result.
0 commit comments