Skip to content
This repository was archived by the owner on Jan 26, 2026. It is now read-only.

Commit 411eeed

Browse files
committed
uri: Only set file scheme for special Windows paths
Fixes 2ce70cd. Also fix a test case.
1 parent 977c076 commit 411eeed

2 files changed

Lines changed: 33 additions & 19 deletions

File tree

testparser.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -415,19 +415,19 @@ testBuildRelativeUri(void) {
415415
}, {
416416
"file:///a/b1/c1",
417417
"/a/b2/c2",
418-
"../b1/c1"
418+
NULL
419419
}, {
420420
"/a/b1/c1",
421421
"file:///a/b2/c2",
422-
"../b1/c1"
422+
NULL
423423
}, {
424424
"a/b1/c1",
425425
"/a/b2/c2",
426426
NULL
427427
}, {
428428
"/a/b1/c1",
429429
"a/b2/c2",
430-
"file:///a/b1/c1"
430+
NULL
431431
}, {
432432
"http://example.org/a/b1/c1",
433433
"http://example.org/a/b2/c2",
@@ -489,11 +489,11 @@ testBuildRelativeUri(void) {
489489
}, {
490490
"/a/b1/c1",
491491
"y:/a/b2/c2",
492-
"file:///a/b1/c1"
492+
NULL
493493
}, {
494-
"\\server\\a\\b1\\c1",
494+
"\\\\server\\a\\b1\\c1",
495495
"a/b2/c2",
496-
"file:///server/a/b1/c1"
496+
"file://server/a/b1/c1"
497497
}
498498
#endif
499499
};

uri.c

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,21 +2397,19 @@ xmlParseUriOrPath(const char *str, xmlURIPtr *out, int *drive) {
23972397
if (xmlIsAbsolutePath(BAD_CAST buf)) {
23982398
#if defined(_WIN32) || defined(__CYGWIN__)
23992399
const char *server = NULL;
2400+
int isFileScheme = 0;
24002401
#endif
24012402

2402-
uri->scheme = (char *) xmlStrdup(BAD_CAST "file");
2403-
if (uri->scheme == NULL) {
2404-
ret = -1;
2405-
goto done;
2406-
}
2407-
24082403
#if defined(_WIN32) || defined(__CYGWIN__)
24092404
if (strncmp(buf, "//?/UNC/", 8) == 0) {
24102405
server = buf + 8;
2406+
isFileScheme = 1;
24112407
} else if (strncmp(buf, "//?/", 4) == 0) {
24122408
path = buf + 3;
2409+
isFileScheme = 1;
24132410
} else if (strncmp(buf, "//", 2) == 0) {
24142411
server = buf + 2;
2412+
isFileScheme = 1;
24152413
}
24162414

24172415
if (server != NULL) {
@@ -2433,12 +2431,22 @@ xmlParseUriOrPath(const char *str, xmlURIPtr *out, int *drive) {
24332431

24342432
if ((((path[0] >= 'A') && (path[0] <= 'Z')) ||
24352433
((path[0] >= 'a') && (path[0] <= 'z'))) &&
2436-
(path[1] == ':'))
2434+
(path[1] == ':')) {
24372435
prependSlash = 1;
2438-
#endif
2436+
isFileScheme = 1;
2437+
}
24392438

2440-
if (uri->server == NULL)
2441-
uri->port = PORT_EMPTY_SERVER;
2439+
if (isFileScheme) {
2440+
uri->scheme = xmlMemStrdup("file");
2441+
if (uri->scheme == NULL) {
2442+
ret = -1;
2443+
goto done;
2444+
}
2445+
2446+
if (uri->server == NULL)
2447+
uri->port = PORT_EMPTY_SERVER;
2448+
}
2449+
#endif
24422450
}
24432451

24442452
pathSize = strlen(path);
@@ -2591,15 +2599,21 @@ xmlBuildRelativeURISafe(const xmlChar * URI, const xmlChar * base,
25912599
remove_path = 1;
25922600
}
25932601

2602+
bptr = (xmlChar *) bas->path;
2603+
rptr = (xmlChar *) ref->path;
2604+
2605+
/*
2606+
* Return URI if URI and base aren't both absolute or relative.
2607+
*/
2608+
if ((bptr[0] == '/') != (rptr[0] == '/'))
2609+
goto done;
2610+
25942611
/*
25952612
* At this point we can compare the two paths
25962613
*/
25972614
{
25982615
int pos = 0;
25992616

2600-
bptr = (xmlChar *) bas->path;
2601-
rptr = (xmlChar *) ref->path;
2602-
26032617
/*
26042618
* Next we compare the two strings and find where they first differ
26052619
*/

0 commit comments

Comments
 (0)