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.path returns forward slashes instead of backslashes on Windows #973

Open
ahoppen opened this issue Oct 10, 2024 · 1 comment
Open

URL.path returns forward slashes instead of backslashes on Windows #973

ahoppen opened this issue Oct 10, 2024 · 1 comment
Labels
windows Issue regarding compiling/running on Windows

Comments

@ahoppen
Copy link
Member

ahoppen commented Oct 10, 2024

print(URL(fileURLWithPath: #"C:\Users\alex"#).path)
print(URL(fileURLWithPath: #"C:/Users/alex"#).path)

Both print statements above print C:/Users/alex. I think they should print C:\Users\alex.

Maybe worth noting: Using withUnsafeFileSystemRepresentation returns backslashes. Should that be exposed through URL.path?

URL(fileURLWithPath: #"C:/Users/alex"#).withUnsafeFileSystemRepresentation {
    print(String(cString: $0!))
}
// prints C:\Users\alex
ahoppen added a commit to ahoppen/sourcekit-lsp that referenced this issue Oct 21, 2024
…disk

`URL.path` returns forward slashes in the path on Windows (swiftlang/swift-foundation#973) where we expect backslashes. Work around that by defining our own `filePath` property that is backed by `withUnsafeFileSystemRepresentation`, which produces backslashes.

rdar://137963660
ahoppen added a commit to ahoppen/sourcekit-lsp that referenced this issue Oct 21, 2024
…disk

`URL.path` returns forward slashes in the path on Windows (swiftlang/swift-foundation#973) where we expect backslashes. Work around that by defining our own `filePath` property that is backed by `withUnsafeFileSystemRepresentation`, which produces backslashes.

rdar://137963660
ahoppen added a commit to ahoppen/sourcekit-lsp that referenced this issue Oct 21, 2024
…disk

`URL.path` returns forward slashes in the path on Windows (swiftlang/swift-foundation#973) where we expect backslashes. Work around that by defining our own `filePath` property that is backed by `withUnsafeFileSystemRepresentation`, which produces backslashes.

rdar://137963660
ahoppen added a commit to ahoppen/sourcekit-lsp that referenced this issue Oct 21, 2024
…disk

`URL.path` returns forward slashes in the path on Windows (swiftlang/swift-foundation#973) where we expect backslashes. Work around that by defining our own `filePath` property that is backed by `withUnsafeFileSystemRepresentation`, which produces backslashes.

rdar://137963660
ahoppen added a commit to ahoppen/sourcekit-lsp that referenced this issue Oct 21, 2024
…disk

`URL.path` returns forward slashes in the path on Windows (swiftlang/swift-foundation#973) where we expect backslashes. Work around that by defining our own `filePath` property that is backed by `withUnsafeFileSystemRepresentation`, which produces backslashes.

rdar://137963660
ahoppen added a commit to ahoppen/sourcekit-lsp that referenced this issue Oct 21, 2024
…disk

`URL.path` returns forward slashes in the path on Windows (swiftlang/swift-foundation#973) where we expect backslashes. Work around that by defining our own `filePath` property that is backed by `withUnsafeFileSystemRepresentation`, which produces backslashes.

rdar://137963660
ahoppen added a commit to ahoppen/sourcekit-lsp that referenced this issue Oct 21, 2024
…disk

`URL.path` returns forward slashes in the path on Windows (swiftlang/swift-foundation#973) where we expect backslashes. Work around that by defining our own `filePath` property that is backed by `withUnsafeFileSystemRepresentation`, which produces backslashes.

rdar://137963660
ahoppen added a commit to ahoppen/sourcekit-lsp that referenced this issue Oct 21, 2024
…disk

`URL.path` returns forward slashes in the path on Windows (swiftlang/swift-foundation#973) where we expect backslashes. Work around that by defining our own `filePath` property that is backed by `withUnsafeFileSystemRepresentation`, which produces backslashes.

rdar://137963660
@jakepetroules
Copy link

jakepetroules commented Dec 8, 2024

Based on my previous experience in this area, it's expected behavior.

If you want the file path associated with a file URL, you must use withUnsafeFileSystemRepresentation. path quite specifically refers to the path component of the URL per RFC8089, which is conceptually not the same thing.

In fact, I'd have expected your example to print /C:/Users/alex (with an extra leading slash), as that's that the RFC specifies. Not sure if the Foundation team changed that to remove the leading slash VERY recently... (EDIT: Yeah: #964)

@jakepetroules jakepetroules added the windows Issue regarding compiling/running on Windows label Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
windows Issue regarding compiling/running on Windows
Projects
None yet
Development

No branches or pull requests

2 participants