1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-08-25 13:49:22 +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 xml; /* xml or txt */
int count; /* how many refs use that specific doc */ int count; /* how many refs use that specific doc */
xmlXPathObjectPtr xptr; /* the xpointer if needed */ xmlXPathObjectPtr xptr; /* the xpointer if needed */
int emptyFb; /* flag to show fallback empty */ int skip; /* skip in case of errors */
}; };
struct _xmlXIncludeCtxt { struct _xmlXIncludeCtxt {
@ -2007,7 +2007,6 @@ xmlXIncludeLoadFallback(xmlXIncludeCtxtPtr ctxt, xmlNodePtr fallback, int nr) {
fallback->children); fallback->children);
} else { } else {
ctxt->incTab[nr]->inc = NULL; ctxt->incTab[nr]->inc = NULL;
ctxt->incTab[nr]->emptyFb = 1; /* flag empty callback */
} }
return(ret); return(ret);
} }
@ -2164,13 +2163,13 @@ xmlXIncludeLoadNode(xmlXIncludeCtxtPtr ctxt, int nr) {
((xmlStrEqual(children->ns->href, XINCLUDE_NS)) || ((xmlStrEqual(children->ns->href, XINCLUDE_NS)) ||
(xmlStrEqual(children->ns->href, XINCLUDE_OLD_NS)))) { (xmlStrEqual(children->ns->href, XINCLUDE_OLD_NS)))) {
ret = xmlXIncludeLoadFallback(ctxt, children, nr); ret = xmlXIncludeLoadFallback(ctxt, children, nr);
if (ret == 0) break;
break;
} }
children = children->next; children = children->next;
} }
} }
if (ret < 0) { if (ret < 0) {
ctxt->incTab[nr]->skip = 1;
xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref, xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref,
XML_XINCLUDE_NO_FALLBACK, XML_XINCLUDE_NO_FALLBACK,
"could not load %s, and no fallback was found\n", "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++) { for (i = ctxt->incBase;i < ctxt->incNr; i++) {
if ((ctxt->incTab[i]->inc != NULL) || if (ctxt->incTab[i]->skip == 0)
(ctxt->incTab[i]->xptr != NULL) ||
(ctxt->incTab[i]->emptyFb != 0)) /* (empty fallback) */
xmlXIncludeIncludeNode(ctxt, i); xmlXIncludeIncludeNode(ctxt, i);
} }