1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-10-26 12:25:09 +03:00

xinclude: Expand includes in xmlXIncludeCopyNode

This should make nested includes work reliably.

Fixes #424.
This commit is contained in:
Nick Wellnhofer 2022-10-22 02:19:22 +02:00
parent 5e4b751f32
commit bc267cb9bc
5 changed files with 38 additions and 1 deletions

View File

@ -0,0 +1,6 @@
<?xml version="1.0"?>
<x xmlns:xinclude="http://www.w3.org/2001/XInclude">
<p>Something</p>
<d><p>Something</p></d>
<d><p>Something</p></d>
</x>

View File

@ -0,0 +1,6 @@
<?xml version="1.0"?>
<x xmlns:xinclude="http://www.w3.org/2001/XInclude">
<p>Something</p>
<d><p>Something</p></d>
<d><p>Something</p></d>
</x>

View File

@ -0,0 +1,5 @@
<x xmlns:xinclude="http://www.w3.org/2001/XInclude">
<p>Something</p>
<d><xinclude:include xpointer="xpointer(//p)"/></d>
<xinclude:include xpointer="xpointer(//d)"/>
</x>

View File

@ -0,0 +1,5 @@
<x xmlns:xinclude="http://www.w3.org/2001/XInclude">
<p>Something</p>
<xinclude:include xpointer="xpointer(//d)"/>
<d><xinclude:include xpointer="xpointer(//p)"/></d>
</x>

View File

@ -91,6 +91,9 @@ struct _xmlXIncludeCtxt {
unsigned long incTotal; /* total number of processed inclusions */
};
static xmlXIncludeRefPtr
xmlXIncludeExpandNode(xmlXIncludeCtxtPtr ctxt, xmlNodePtr node);
static int
xmlXIncludeLoadNode(xmlXIncludeCtxtPtr ctxt, int nr);
@ -848,7 +851,19 @@ xmlXIncludeCopyNode(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target,
if (elem->type == XML_DOCUMENT_NODE)
result = xmlXIncludeCopyNodeList(ctxt, target, source, elem->children,
NULL);
else {
else if ((elem->type == XML_ELEMENT_NODE) &&
(elem->ns != NULL) &&
(xmlStrEqual(elem->name, XINCLUDE_NODE)) &&
((xmlStrEqual(elem->ns->href, XINCLUDE_NS)) ||
(xmlStrEqual(elem->ns->href, XINCLUDE_OLD_NS)))) {
xmlXIncludeRefPtr ref = xmlXIncludeExpandNode(ctxt, elem);
/*
* TODO: Insert XML_XINCLUDE_START and XML_XINCLUDE_END nodes
*/
if ((ref != NULL) && (ref->inc != NULL))
result = xmlDocCopyNodeList(target, ref->inc);
} else {
result = xmlDocCopyNode(elem, target, 2);
if (result == NULL)
return(NULL);