Skip to content
This repository was archived by the owner on Jan 26, 2026. It is now read-only.

Commit a0330b5

Browse files
committed
xinclude: Fix fallback for text includes
Fixes #772.
1 parent 8699ba2 commit a0330b5

5 files changed

Lines changed: 25 additions & 1 deletion

File tree

result/XInclude/fallback8.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0"?>
2+
<doc>
3+
text not found
4+
</doc>

result/XInclude/fallback8.xml.err

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
I/O warning : failed to load "test/XInclude/docs/404.txt": No such file or directory

result/XInclude/fallback8.xml.rdr

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
0 1 doc 0 0
2+
1 14 #text 0 1
3+
4+
1 3 #text 0 1 text not found
5+
1 14 #text 0 1
6+
7+
0 15 doc 0 0

test/XInclude/docs/fallback8.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0"?>
2+
<doc>
3+
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="404.txt" parse="text">
4+
<xi:fallback>text not found</xi:fallback>
5+
</xi:include>
6+
</doc>
7+

xinclude.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1655,9 +1655,14 @@ xmlXIncludeLoadTxt(xmlXIncludeCtxtPtr ctxt, xmlXIncludeRefPtr ref) {
16551655
}
16561656
inputStream = xmlLoadExternalEntity((const char*)url, NULL, pctxt);
16571657
if (inputStream == NULL) {
1658+
/*
1659+
* ENOENT only produces a warning which isn't reflected in errNo.
1660+
*/
16581661
if (pctxt->errNo == XML_ERR_NO_MEMORY)
16591662
xmlXIncludeErrMemory(ctxt);
1660-
else
1663+
else if ((pctxt->errNo != XML_ERR_OK) &&
1664+
(pctxt->errNo != XML_IO_ENOENT) &&
1665+
(pctxt->errNo != XML_IO_UNKNOWN))
16611666
xmlXIncludeErr(ctxt, NULL, pctxt->errNo, "load error", NULL);
16621667
goto error;
16631668
}

0 commit comments

Comments
 (0)