mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-03-10 08:58:16 +03:00
add a new function xmlPathToUri() to provide a clean conversion when
* uri.c include/libxml/uri.h: add a new function xmlPathToUri() to provide a clean conversion when setting up a base * SAX2.c tree.c: use said function when setting up doc->URL or using the xmlSetBase function. Should fix #346261 Daniel
This commit is contained in:
parent
0da4166676
commit
b8efdda0a3
@ -1,3 +1,10 @@
|
||||
Tue Oct 10 14:36:18 CEST 2006 Daniel Veillard <daniel@veillard.com>
|
||||
|
||||
* uri.c include/libxml/uri.h: add a new function xmlPathToUri()
|
||||
to provide a clean conversion when setting up a base
|
||||
* SAX2.c tree.c: use said function when setting up doc->URL
|
||||
or using the xmlSetBase function. Should fix #346261
|
||||
|
||||
Tue Oct 10 11:05:59 CEST 2006 Daniel Veillard <daniel@veillard.com>
|
||||
|
||||
* xmlIO.c: applied a portability patch from Emelyanov Alexey
|
||||
|
2
SAX2.c
2
SAX2.c
@ -987,7 +987,7 @@ xmlSAX2StartDocument(void *ctx)
|
||||
}
|
||||
if ((ctxt->myDoc != NULL) && (ctxt->myDoc->URL == NULL) &&
|
||||
(ctxt->input != NULL) && (ctxt->input->filename != NULL)) {
|
||||
ctxt->myDoc->URL = xmlCanonicPath((const xmlChar *) ctxt->input->filename);
|
||||
ctxt->myDoc->URL = xmlPathToURI((const xmlChar *)ctxt->input->filename);
|
||||
if (ctxt->myDoc->URL == NULL)
|
||||
xmlSAX2ErrMemory(ctxt, "xmlSAX2StartDocument");
|
||||
}
|
||||
|
@ -80,6 +80,8 @@ XMLPUBFUN void XMLCALL
|
||||
xmlFreeURI (xmlURIPtr uri);
|
||||
XMLPUBFUN xmlChar* XMLCALL
|
||||
xmlCanonicPath (const xmlChar *path);
|
||||
XMLPUBFUN xmlChar* XMLCALL
|
||||
xmlPathToURI (const xmlChar *path);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
11
tree.c
11
tree.c
@ -4800,6 +4800,7 @@ xmlNodeSetName(xmlNodePtr cur, const xmlChar *name) {
|
||||
void
|
||||
xmlNodeSetBase(xmlNodePtr cur, const xmlChar* uri) {
|
||||
xmlNsPtr ns;
|
||||
const xmlChar* fixed;
|
||||
|
||||
if (cur == NULL) return;
|
||||
switch(cur->type) {
|
||||
@ -4835,7 +4836,7 @@ xmlNodeSetBase(xmlNodePtr cur, const xmlChar* uri) {
|
||||
if (uri == NULL)
|
||||
doc->URL = NULL;
|
||||
else
|
||||
doc->URL = xmlStrdup(uri);
|
||||
doc->URL = xmlPathToURI(uri);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -4843,7 +4844,13 @@ xmlNodeSetBase(xmlNodePtr cur, const xmlChar* uri) {
|
||||
ns = xmlSearchNsByHref(cur->doc, cur, XML_XML_NAMESPACE);
|
||||
if (ns == NULL)
|
||||
return;
|
||||
xmlSetNsProp(cur, ns, BAD_CAST "base", uri);
|
||||
fixed = xmlPathToURI(uri);
|
||||
if (fixed != NULL) {
|
||||
xmlSetNsProp(cur, ns, BAD_CAST "base", fixed);
|
||||
xmlFree(fixed);
|
||||
} else {
|
||||
xmlSetNsProp(cur, ns, BAD_CAST "base", uri);
|
||||
}
|
||||
}
|
||||
#endif /* LIBXML_TREE_ENABLED */
|
||||
|
||||
|
58
uri.c
58
uri.c
@ -2343,7 +2343,7 @@ done:
|
||||
(((p[0] >= 'a') && (p[0] <= 'z')) || \
|
||||
((p[0] >= 'A') && (p[0] <= 'Z'))) && \
|
||||
(p[1] == ':') && ((p[2] == '/') || (p[2] == '\\')))
|
||||
xmlChar*
|
||||
xmlChar *
|
||||
xmlCanonicPath(const xmlChar *path)
|
||||
{
|
||||
#if defined(_WIN32) && !defined(__CYGWIN__)
|
||||
@ -2406,12 +2406,20 @@ path_processing:
|
||||
len = xmlStrlen(path);
|
||||
if ((len > 2) && IS_WINDOWS_PATH(path)) {
|
||||
uri->scheme = xmlStrdup(BAD_CAST "file");
|
||||
uri->path = xmlMallocAtomic(len + 2); /* FIXME - check alloc! */
|
||||
uri->path = xmlMallocAtomic(len + 2);
|
||||
if (uri->path == NULL) {
|
||||
xmlFreeURI(uri);
|
||||
return(NULL);
|
||||
}
|
||||
uri->path[0] = '/';
|
||||
p = uri->path + 1;
|
||||
strncpy(p, path, len + 1);
|
||||
} else {
|
||||
uri->path = xmlStrdup(path); /* FIXME - check alloc! */
|
||||
uri->path = xmlStrdup(path);
|
||||
if (uri->path == NULL) {
|
||||
xmlFreeURI(uri);
|
||||
return(NULL);
|
||||
}
|
||||
p = uri->path;
|
||||
}
|
||||
while (*p != '\0') {
|
||||
@ -2424,11 +2432,11 @@ path_processing:
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
if (uri->scheme == NULL) {
|
||||
ret = xmlStrdup((const xmlChar *) path);
|
||||
} else {
|
||||
ret = xmlSaveUri(uri);
|
||||
}
|
||||
if (uri->scheme == NULL) {
|
||||
ret = xmlStrdup((const xmlChar *) path);
|
||||
} else {
|
||||
ret = xmlSaveUri(uri);
|
||||
}
|
||||
|
||||
xmlFreeURI(uri);
|
||||
#else
|
||||
@ -2437,5 +2445,39 @@ path_processing:
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlPathToURI:
|
||||
* @path: the resource locator in a filesystem notation
|
||||
*
|
||||
* Constructs an URI expressing the existing path
|
||||
*
|
||||
* Returns a new URI, or a duplicate of the path parameter if the
|
||||
* construction fails. The caller is responsible for freeing the memory
|
||||
* occupied by the returned string. If there is insufficient memory available,
|
||||
* or the argument is NULL, the function returns NULL.
|
||||
*/
|
||||
xmlChar *
|
||||
xmlPathToURI(const xmlChar *path)
|
||||
{
|
||||
xmlURIPtr uri;
|
||||
xmlURI temp;
|
||||
xmlChar *ret, *cal;
|
||||
|
||||
if (path == NULL)
|
||||
return(NULL);
|
||||
|
||||
if ((uri = xmlParseURI((const char *) path)) != NULL) {
|
||||
xmlFreeURI(uri);
|
||||
return xmlStrdup(path);
|
||||
}
|
||||
cal = xmlCanonicPath(path);
|
||||
if (cal == NULL)
|
||||
return(NULL);
|
||||
memset(&temp, 0, sizeof(temp));
|
||||
temp.path = (char *) cal;
|
||||
ret = xmlSaveUri(&temp);
|
||||
xmlFree(cal);
|
||||
return(ret);
|
||||
}
|
||||
#define bottom_uri
|
||||
#include "elfgcchack.h"
|
||||
|
Loading…
x
Reference in New Issue
Block a user