Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL.withUnsafeFileSystemRepresentation drops trailing backslash even if it is significant on Windows #976

Closed
ahoppen opened this issue Oct 10, 2024 · 0 comments · Fixed by #1038
Assignees

Comments

@ahoppen
Copy link
Member

ahoppen commented Oct 10, 2024

let url = URL(fileURLWithPath: #"C:\"#)
url.withUnsafeFileSystemRepresentation { filePath in
    print(String(cString: filePath! , encoding: .utf8))
}

prints C:. Dropping the trailing backslash is problematic here because C:\ is considered a root directory in Windows but C: is not (see table of examples in https://learn.microsoft.com/en-us/windows/win32/api/pathcch/nf-pathcch-pathcchisroot).

@jrflat jrflat self-assigned this Oct 16, 2024
macshome added a commit to macshome/swift-format that referenced this issue Dec 6, 2024
Now that swiftlang/swift-foundation#976 and swiftlang/swift-foundation#980 are fixed we can clean this code up a bit by removing the empty path check on Linux and by using the native `PathCchIsRoot` on Windows.
macshome added a commit to macshome/swift-format that referenced this issue Dec 9, 2024
Now that swiftlang/swift-foundation#976 and swiftlang/swift-foundation#980 are fixed we can clean this code up a bit by removing the empty path check on Linux and by using the native `PathCchIsRoot` on Windows.

Existing code is retained for toolchains <6.1
macshome added a commit to macshome/swift-format that referenced this issue Dec 10, 2024
Now that swiftlang/swift-foundation#976 and swiftlang/swift-foundation#980 are fixed we can clean this code up a bit by removing the empty path check on Linux and by using the native `PathCchIsRoot` on Windows.

Existing code is retained for toolchains <6.1
ahoppen pushed a commit to macshome/swift-format that referenced this issue Dec 10, 2024
Now that swiftlang/swift-foundation#976 and swiftlang/swift-foundation#980 are fixed we can clean this code up a bit by removing the empty path check on Linux and by using the native `PathCchIsRoot` on Windows.

Existing code is retained for toolchains <6.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants