diff options
author | Thomas Holder <thomas.holder@schrodinger.com> | 2018-11-05 14:20:16 +0100 |
---|---|---|
committer | Daniel Veillard <veillard@redhat.com> | 2018-11-29 22:19:44 +0100 |
commit | b1f87c0e4376a993e682f59471e2c455a9179e22 (patch) | |
tree | 5aad37547e7a8b89ac6dbd8055ffbfdf11dd8b48 /uri.c | |
parent | 25f13e77e6ce47e7a87559813e802ffb8c3b957f (diff) | |
download | libxml2-b1f87c0e4376a993e682f59471e2c455a9179e22.tar.gz |
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/
Diffstat (limited to 'uri.c')
-rw-r--r-- | uri.c | 22 |
1 files changed, 11 insertions, 11 deletions
@@ -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; } |