1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2026-10-24 01:09:01 +03:00

xmlreader: Copy DTD in xmlTextReaderDumpCopy

This patch makes sure that the XML_DTD_NODE is copied during the
xmlTextReaderDumpCopy.

With this change, the xmlStaticCopyNode function now copies XML_DTD_NODE
instead of returning NULL.

Fix https://gitlab.gnome.org/GNOME/libxml2/-/issues/1108
This commit is contained in:
Daniel Garcia Moreno
2026-04-27 14:42:15 +02:00
committed by Daniel Garcia Moreno
parent 107b56582c
commit 39b66eb208
3 changed files with 51 additions and 4 deletions

View File

@@ -2884,6 +2884,50 @@ xmlReaderForFdGzTest(const char *filename, const char *result ATTRIBUTE_UNUSED,
#endif
#ifdef LIBXML_READER_ENABLED
/**
* Checking that xmlTextReaderReadOuterXml copy the XML_DTD_NODE
*
* xmlTextReaderReadOuterXml does not copy XML_DTD_NODE since libxml2 2.13.0
* https://gitlab.gnome.org/GNOME/libxml2/-/issues/1108
*/
static int
xmlTextReaderReadOuterXmlTest(const char *filename ATTRIBUTE_UNUSED,
const char *result ATTRIBUTE_UNUSED,
const char *err ATTRIBUTE_UNUSED,
int options ATTRIBUTE_UNUSED) {
xmlTextReaderPtr reader = NULL;
int ret = 0;
int res = 1;
xmlChar *out = NULL;
const char *doc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\""
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">"
"<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"400\" height=\"300\">"
" <rect width=\"400\" height=\"300\" fill=\"white\"/>"
"</svg>";
reader = xmlReaderForMemory(doc, strlen(doc), "doc.svg", NULL, XML_PARSE_NOENT);
while (res == 1) {
res = xmlTextReaderRead(reader);
if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_DOCUMENT_TYPE) {
out = xmlTextReaderReadOuterXml(reader);
ret = xmlStrEqual(out, BAD_CAST "<!DOCTYPE svg PUBLIC \"-//W3C//DTD //SVG //1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">") == 1;
if (out != NULL) {
xmlFree(out);
out = NULL;
}
break;
}
}
xmlFreeTextReader(reader);
return(ret);
}
#endif
/**
* Parse a file using the reader API and check for errors.
*
@@ -5560,7 +5604,10 @@ testDesc testDescriptions[] = {
xmlReaderForFdGzTest, "./test/slashdot.xml", NULL, NULL, NULL, 0 },
#endif
#endif
#if defined(LIBXML_OUTPUT_ENABLED) && defined(LIBXML_READER_ENABLED)
{ "xmlTextReaderReadOuterXml copy XML_DTD_NODE",
xmlTextReaderReadOuterXmlTest, NULL, NULL, NULL, NULL, 0 },
#endif
{ "xmlCopyEntity children test" , xmlCopyEntityTest, NULL, NULL, NULL, NULL, 0 },
{NULL, NULL, NULL, NULL, NULL, NULL, 0}

3
tree.c
View File

@@ -3876,7 +3876,8 @@ xmlStaticCopyNode(xmlNode *node, xmlDoc *doc, xmlNode *parent,
return((xmlNodePtr) xmlCopyPropInternal(doc, parent, (xmlAttrPtr) node));
case XML_NAMESPACE_DECL:
return((xmlNodePtr) xmlCopyNamespaceList((xmlNsPtr) node));
case XML_DTD_NODE:
return((xmlNodePtr) xmlCopyDtd((xmlDtdPtr) node));
case XML_DOCUMENT_NODE:
case XML_HTML_DOCUMENT_NODE:
return((xmlNodePtr) xmlCopyDoc((xmlDocPtr) node, extended));

View File

@@ -1617,8 +1617,7 @@ xmlTextReaderNext(xmlTextReader *reader) {
static void
xmlTextReaderDumpCopy(xmlTextReaderPtr reader, xmlOutputBufferPtr output,
xmlNodePtr node) {
if ((node->type == XML_DTD_NODE) ||
(node->type == XML_ELEMENT_DECL) ||
if ((node->type == XML_ELEMENT_DECL) ||
(node->type == XML_ATTRIBUTE_DECL) ||
(node->type == XML_ENTITY_DECL))
return;