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

Fix corner case with empty xi:fallback

xi:fallback could become empty after recursive expansion. Use a flag
to track whether nodes should be skipped.
This commit is contained in:
Nick Wellnhofer 2020-08-16 23:38:48 +02:00
parent 00a86d414b
commit d88df4bd48
4 changed files with 11 additions and 7 deletions

View File

@ -0,0 +1 @@
<?xml version="1.0"?>

View File

View File

@ -0,0 +1,6 @@
<?xml version="1.0"?>
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="b.xml">
<xi:fallback><xi:include href="c.xml">
<xi:fallback/>
</xi:include></xi:fallback>
</xi:include>

View File

@ -60,7 +60,7 @@ struct _xmlXIncludeRef {
int xml; /* xml or txt */
int count; /* how many refs use that specific doc */
xmlXPathObjectPtr xptr; /* the xpointer if needed */
int emptyFb; /* flag to show fallback empty */
int skip; /* skip in case of errors */
};
struct _xmlXIncludeCtxt {
@ -2007,7 +2007,6 @@ xmlXIncludeLoadFallback(xmlXIncludeCtxtPtr ctxt, xmlNodePtr fallback, int nr) {
fallback->children);
} else {
ctxt->incTab[nr]->inc = NULL;
ctxt->incTab[nr]->emptyFb = 1; /* flag empty callback */
}
return(ret);
}
@ -2164,13 +2163,13 @@ xmlXIncludeLoadNode(xmlXIncludeCtxtPtr ctxt, int nr) {
((xmlStrEqual(children->ns->href, XINCLUDE_NS)) ||
(xmlStrEqual(children->ns->href, XINCLUDE_OLD_NS)))) {
ret = xmlXIncludeLoadFallback(ctxt, children, nr);
if (ret == 0)
break;
break;
}
children = children->next;
}
}
if (ret < 0) {
ctxt->incTab[nr]->skip = 1;
xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref,
XML_XINCLUDE_NO_FALLBACK,
"could not load %s, and no fallback was found\n",
@ -2468,9 +2467,7 @@ xmlXIncludeDoProcess(xmlXIncludeCtxtPtr ctxt, xmlDocPtr doc, xmlNodePtr tree,
*
*/
for (i = ctxt->incBase;i < ctxt->incNr; i++) {
if ((ctxt->incTab[i]->inc != NULL) ||
(ctxt->incTab[i]->xptr != NULL) ||
(ctxt->incTab[i]->emptyFb != 0)) /* (empty fallback) */
if (ctxt->incTab[i]->skip == 0)
xmlXIncludeIncludeNode(ctxt, i);
}