1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-01-12 09:17:37 +03:00

Fix error reporting with xi:fallback

When reporting errors, don't use href of xi:include if xi:fallback
was used. I think this can only be reproduced with
"xmllint --postvalid", see the original bug report:

https://bugzilla.gnome.org/show_bug.cgi?id=152623
This commit is contained in:
Nick Wellnhofer 2020-08-17 00:54:12 +02:00
parent 27119ec33c
commit 2c74712977
2 changed files with 15 additions and 11 deletions

22
error.c
View File

@ -557,6 +557,7 @@ __xmlRaiseError(xmlStructuredErrorFunc schannel,
* of the usual "base" (doc->URL) for the node (bug 152623).
*/
xmlNodePtr prev = baseptr;
char *href = NULL;
int inclcount = 0;
while (prev != NULL) {
if (prev->prev == NULL)
@ -564,21 +565,20 @@ __xmlRaiseError(xmlStructuredErrorFunc schannel,
else {
prev = prev->prev;
if (prev->type == XML_XINCLUDE_START) {
if (--inclcount < 0)
break;
if (inclcount > 0) {
--inclcount;
} else {
href = (char *) xmlGetProp(prev, BAD_CAST "href");
if (href != NULL)
break;
}
} else if (prev->type == XML_XINCLUDE_END)
inclcount++;
}
}
if (prev != NULL) {
if (prev->type == XML_XINCLUDE_START) {
prev->type = XML_ELEMENT_NODE;
to->file = (char *) xmlGetProp(prev, BAD_CAST "href");
prev->type = XML_XINCLUDE_START;
} else {
to->file = (char *) xmlGetProp(prev, BAD_CAST "href");
}
} else
if (href != NULL)
to->file = href;
else
#endif
to->file = (char *) xmlStrdup(baseptr->doc->URL);
if ((to->file == NULL) && (node != NULL) && (node->doc != NULL)) {

View File

@ -61,6 +61,7 @@ struct _xmlXIncludeRef {
int count; /* how many refs use that specific doc */
xmlXPathObjectPtr xptr; /* the xpointer if needed */
int skip; /* skip in case of errors */
int fallback; /* fallback was loaded */
};
struct _xmlXIncludeCtxt {
@ -2007,6 +2008,7 @@ xmlXIncludeLoadFallback(xmlXIncludeCtxtPtr ctxt, xmlNodePtr fallback, int nr) {
} else {
ctxt->incTab[nr]->inc = NULL;
}
ctxt->incTab[nr]->fallback = 1;
return(ret);
}
@ -2266,6 +2268,8 @@ xmlXIncludeIncludeNode(xmlXIncludeCtxtPtr ctxt, int nr) {
* Change the current node as an XInclude start one, and add an
* XInclude end one
*/
if (ctxt->incTab[nr]->fallback)
xmlUnsetProp(cur, BAD_CAST "href");
cur->type = XML_XINCLUDE_START;
end = xmlNewDocNode(cur->doc, cur->ns, cur->name, NULL);
if (end == NULL) {