Skip to content

Commit 45fea3c

Browse files
committed
CoreFoundation: handle isDirectory properly in WindowsPathToURLPath
In the case that we were given a non-directory path terminating in `\`, we would preserve the last path arc constructing a directory path instead of a file path. This manifested as test failure in the Swift test suite when converting paths.
1 parent 6167997 commit 45fea3c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

CoreFoundation/URL.subproj/CFURL.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3977,6 +3977,13 @@ static CFArrayRef WindowsPathToURLComponents(CFStringRef path, CFAllocatorRef al
39773977
urlComponents = CFArrayCreateMutableCopy(alloc, 0, tmp);
39783978
CFRelease(tmp);
39793979

3980+
if (isDir == FALSE) {
3981+
CFIndex last = CFArrayGetCount(urlComponents) - 1;
3982+
if (CFEqual(CFArrayGetValueAtIndex(urlComponents, last), CFSTR(""))) {
3983+
CFArrayRemoveValueAtIndex(urlComponents, last);
3984+
}
3985+
}
3986+
39803987
CFStringRef str = (CFStringRef)CFArrayGetValueAtIndex(urlComponents, 0);
39813988
if (isAbsolute && CFStringGetLength(str) == 2 && CFStringGetCharacterAtIndex(str, 1) == ':') {
39823989
i = 1; // Skip over the drive letter

0 commit comments

Comments
 (0)