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

Windows file URL prepends "/" at beginning of path property, breaking compatibility #857

Open
gregcotten opened this issue Aug 15, 2024 · 3 comments
Assignees

Comments

@gregcotten
Copy link

gregcotten commented Aug 15, 2024

For example, initialize a simple file URL and print its path:

let url = URL(fileURLWithPath: "C:/Test")
print(url.path)

In Swift 5.10.1, you get: C:/Test
In Swift 6.0 (August 7 snapshot) you get: /C:/Test

Maybe this is intended, but it definitely breaks my usage of passing file URL paths as arguments into a spawned Process for my build tools.

@gregcotten gregcotten changed the title Windows file URL prepends "/" at beginning of path property Windows file URL prepends "/" at beginning of path property, breaking compatibility Aug 15, 2024
@jmschonfeld
Copy link
Contributor

@jrflat I believe this is the new behavior of URL, so you might be able to look into this. @gregcotten I'd be interested hearing more about how this breaks your use of Process as I'd expect Process itself should still handle this (as URL.withUnsafeFileSystemRepresentation and FileManager.fileSystemRepresentation which are used to provide file system paths to C APIs should still handle this case and remove the leading slash) so at a minimum we should probably correct Process to account for this (I updated Process to correct the executable path with swiftlang/swift-corelibs-foundation#4999)

@gregcotten
Copy link
Author

Interesting! I guess my issue with path being RFC8089 is that it's a rather large change, especially for me :)

I often use someURL.path as a way of communicating a path to a non-Swift party, like calling out to an external process from Swift with a someURL.path as an argument, or in the case of our Electron app, communicating with their JS backend about presenting a save file dialog with a specified path, etc...

@jrflat
Copy link
Contributor

jrflat commented Aug 15, 2024

@jmschonfeld Yeah I think we were just discussing there could be merit in moving Windows path logic (replacing / with \, removing leading slash if there's a drive letter) to URL.fileSystemPath, which is vended to URL.path for compatibility. I can look into that.

@jrflat jrflat self-assigned this Aug 15, 2024
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

No branches or pull requests

3 participants