[libxml2] Fix recursion check in xinclude.c



commit bc06a522c10cbf491cfef4f82f169532e04044a1
Author: Nick Wellnhofer <wellnhofer aevum de>
Date:   Wed Mar 2 02:57:49 2022 +0100

    Fix recursion check in xinclude.c
    
    Compare the included URL with the document's URL to detect local
    inclusions.
    
    Fixes #348.

 result/XInclude/red.xml     |  9 +++++++++
 result/XInclude/red.xml.rdr | 26 ++++++++++++++++++++++++++
 test/XInclude/docs/red.xml  | 10 ++++++++++
 xinclude.c                  |  5 +++--
 4 files changed, 48 insertions(+), 2 deletions(-)
---
diff --git a/result/XInclude/red.xml b/result/XInclude/red.xml
new file mode 100644
index 00000000..87adf844
--- /dev/null
+++ b/result/XInclude/red.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<book xmlns:xi="http://www.w3.org/2001/XInclude"; xmlns:xlink="http://www.w3.org/1999/xlink";>
+  <chapter>
+     <para xml:id="t100">Introduction</para>
+  </chapter>
+  <chapter>
+     <para xml:id="t100">Introduction</para>
+  </chapter>
+</book>
diff --git a/result/XInclude/red.xml.rdr b/result/XInclude/red.xml.rdr
new file mode 100644
index 00000000..de332dbc
--- /dev/null
+++ b/result/XInclude/red.xml.rdr
@@ -0,0 +1,26 @@
+0 1 book 0 0
+1 14 #text 0 1 
+  
+1 1 chapter 0 0
+2 14 #text 0 1 
+     
+2 1 para 0 0
+3 3 #text 0 1 Introduction
+2 15 para 0 0
+2 14 #text 0 1 
+  
+1 15 chapter 0 0
+1 14 #text 0 1 
+  
+1 1 chapter 0 0
+2 14 #text 0 1 
+     
+2 1 para 0 0
+3 3 #text 0 1 Introduction
+2 15 para 0 0
+2 14 #text 0 1 
+  
+1 15 chapter 0 0
+1 14 #text 0 1 
+
+0 15 book 0 0
diff --git a/test/XInclude/docs/red.xml b/test/XInclude/docs/red.xml
new file mode 100644
index 00000000..75ee396d
--- /dev/null
+++ b/test/XInclude/docs/red.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<book xmlns:xi="http://www.w3.org/2001/XInclude";
+      xmlns:xlink="http://www.w3.org/1999/xlink";>
+  <chapter>
+     <para xml:id="t100">Introduction</para>
+  </chapter>
+  <chapter>
+     <xi:include href="./red.xml" xpointer="t100" parse="xml"/>
+  </chapter>
+</book>
diff --git a/xinclude.c b/xinclude.c
index 4f5b6846..ae5fd5de 100644
--- a/xinclude.c
+++ b/xinclude.c
@@ -525,8 +525,6 @@ xmlXIncludeAddNode(xmlXIncludeCtxtPtr ctxt, xmlNodePtr cur) {
        if (href == NULL)
            return(-1);
     }
-    if ((href[0] == '#') || (href[0] == 0))
-       local = 1;
     parse = xmlXIncludeGetProp(ctxt, cur, XINCLUDE_PARSE);
     if (parse != NULL) {
        if (xmlStrEqual(parse, XINCLUDE_PARSE_XML))
@@ -623,6 +621,9 @@ xmlXIncludeAddNode(xmlXIncludeCtxtPtr ctxt, xmlNodePtr cur) {
        return(-1);
     }
 
+    if (xmlStrEqual(URL, ctxt->doc->URL))
+       local = 1;
+
     /*
      * If local and xml then we need a fragment
      */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]