[libxml2] Fix building relative URIs



commit b1f87c0e4376a993e682f59471e2c455a9179e22
Author: Thomas Holder <thomas holder schrodinger com>
Date:   Mon Nov 5 14:20:16 2018 +0100

    Fix building relative URIs
    
    Examples:
    
    testURI --relative --base file:///a file:///b
    New correct result: b
    Old incorrect result: ../b
    
    testURI --relative --base file:///a file:///
    New correct result: ./
    Old incorrect result: ../
    
    testURI --relative --base file:///a/b file:///a/
    New correct result: ./
    Old incorrect result: ../../a/

 uri.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
---
diff --git a/uri.c b/uri.c
index 84e420a0..4901a117 100644
--- a/uri.c
+++ b/uri.c
@@ -2280,20 +2280,11 @@ xmlBuildRelativeURI (const xmlChar * URI, const xmlChar * base)
         * beginning of the "unique" suffix of URI
         */
        ix = pos;
-       if ((rptr[ix] == '/') && (ix > 0))
-           ix--;
-       else if ((rptr[ix] == 0) && (ix > 1) && (rptr[ix - 1] == '/'))
-           ix -= 2;
        for (; ix > 0; ix--) {
-           if (rptr[ix] == '/')
+           if (rptr[ix - 1] == '/')
                break;
        }
-       if (ix == 0) {
-           uptr = (xmlChar *)rptr;
-       } else {
-           ix++;
-           uptr = (xmlChar *)&rptr[ix];
-       }
+       uptr = (xmlChar *)&rptr[ix];
 
        /*
         * In base, count the number of '/' from the differing point
@@ -2304,6 +2295,15 @@ xmlBuildRelativeURI (const xmlChar * URI, const xmlChar * base)
                    nbslash++;
            }
        }
+
+       /*
+        * e.g: URI="foo/" base="foo/bar" -> "./"
+        */
+       if (nbslash == 0 && !uptr[0]) {
+           val = xmlStrdup(BAD_CAST "./");
+           goto done;
+       }
+
        len = xmlStrlen (uptr) + 1;
     }
 


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