1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-23 01:52:48 +03:00

uri: Only set file scheme for special Windows paths

Fixes 2ce70cde.

Also fix a test case.
This commit is contained in:
Nick Wellnhofer
2024-06-23 21:51:52 +02:00
parent ec47add47c
commit 54c6c7e416
2 changed files with 33 additions and 19 deletions

View File

@@ -416,11 +416,11 @@ testBuildRelativeUri(void) {
}, { }, {
"file:///a/b1/c1", "file:///a/b1/c1",
"/a/b2/c2", "/a/b2/c2",
"../b1/c1" NULL
}, { }, {
"/a/b1/c1", "/a/b1/c1",
"file:///a/b2/c2", "file:///a/b2/c2",
"../b1/c1" NULL
}, { }, {
"a/b1/c1", "a/b1/c1",
"/a/b2/c2", "/a/b2/c2",
@@ -428,7 +428,7 @@ testBuildRelativeUri(void) {
}, { }, {
"/a/b1/c1", "/a/b1/c1",
"a/b2/c2", "a/b2/c2",
"file:///a/b1/c1" NULL
}, { }, {
"http://example.org/a/b1/c1", "http://example.org/a/b1/c1",
"http://example.org/a/b2/c2", "http://example.org/a/b2/c2",
@@ -490,11 +490,11 @@ testBuildRelativeUri(void) {
}, { }, {
"/a/b1/c1", "/a/b1/c1",
"y:/a/b2/c2", "y:/a/b2/c2",
"file:///a/b1/c1" NULL
}, { }, {
"\\server\\a\\b1\\c1", "\\\\server\\a\\b1\\c1",
"a/b2/c2", "a/b2/c2",
"file:///server/a/b1/c1" "file://server/a/b1/c1"
} }
#endif #endif
}; };

40
uri.c
View File

@@ -2397,21 +2397,19 @@ xmlParseUriOrPath(const char *str, xmlURIPtr *out, int *drive) {
if (xmlIsAbsolutePath(BAD_CAST buf)) { if (xmlIsAbsolutePath(BAD_CAST buf)) {
#if defined(_WIN32) || defined(__CYGWIN__) #if defined(_WIN32) || defined(__CYGWIN__)
const char *server = NULL; const char *server = NULL;
int isFileScheme = 0;
#endif #endif
uri->scheme = (char *) xmlStrdup(BAD_CAST "file");
if (uri->scheme == NULL) {
ret = -1;
goto done;
}
#if defined(_WIN32) || defined(__CYGWIN__) #if defined(_WIN32) || defined(__CYGWIN__)
if (strncmp(buf, "//?/UNC/", 8) == 0) { if (strncmp(buf, "//?/UNC/", 8) == 0) {
server = buf + 8; server = buf + 8;
isFileScheme = 1;
} else if (strncmp(buf, "//?/", 4) == 0) { } else if (strncmp(buf, "//?/", 4) == 0) {
path = buf + 3; path = buf + 3;
isFileScheme = 1;
} else if (strncmp(buf, "//", 2) == 0) { } else if (strncmp(buf, "//", 2) == 0) {
server = buf + 2; server = buf + 2;
isFileScheme = 1;
} }
if (server != NULL) { if (server != NULL) {
@@ -2433,12 +2431,22 @@ xmlParseUriOrPath(const char *str, xmlURIPtr *out, int *drive) {
if ((((path[0] >= 'A') && (path[0] <= 'Z')) || if ((((path[0] >= 'A') && (path[0] <= 'Z')) ||
((path[0] >= 'a') && (path[0] <= 'z'))) && ((path[0] >= 'a') && (path[0] <= 'z'))) &&
(path[1] == ':')) (path[1] == ':')) {
prependSlash = 1; prependSlash = 1;
#endif isFileScheme = 1;
}
if (uri->server == NULL) if (isFileScheme) {
uri->port = PORT_EMPTY_SERVER; uri->scheme = xmlMemStrdup("file");
if (uri->scheme == NULL) {
ret = -1;
goto done;
}
if (uri->server == NULL)
uri->port = PORT_EMPTY_SERVER;
}
#endif
} }
pathSize = strlen(path); pathSize = strlen(path);
@@ -2591,15 +2599,21 @@ xmlBuildRelativeURISafe(const xmlChar * URI, const xmlChar * base,
remove_path = 1; remove_path = 1;
} }
bptr = (xmlChar *) bas->path;
rptr = (xmlChar *) ref->path;
/*
* Return URI if URI and base aren't both absolute or relative.
*/
if ((bptr[0] == '/') != (rptr[0] == '/'))
goto done;
/* /*
* At this point we can compare the two paths * At this point we can compare the two paths
*/ */
{ {
int pos = 0; int pos = 0;
bptr = (xmlChar *) bas->path;
rptr = (xmlChar *) ref->path;
/* /*
* Next we compare the two strings and find where they first differ * Next we compare the two strings and find where they first differ
*/ */