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.init(string:) handling of unix file paths has changed in Swift 6 #958

Open
rnro opened this issue Oct 2, 2024 · 1 comment
Open

Comments

@rnro
Copy link

rnro commented Oct 2, 2024

Initializing a URL from a unix file path in Swift 6 on Linux now returns a non-nil value (an empty String). In earlier Swift versions and on macOS it returns nil.

On Linux Swift 5.10:

  1> import Foundation
  2> let u = Foundation.URL(string: "unix:///tmp/file")
  [snip]
  3> print(u!.host)
nil

On Linux Swift 6.0.1:

  1> import Foundation
  2> let u = Foundation.URL(string: "unix:///tmp/file")
  [snip]
  3> print(u!.host)
Optional("")
rnro added a commit to swift-server/async-http-client that referenced this issue Oct 3, 2024
`Foundation.URL` has various behavior changes in Swift 6 to better match
RFC 3986 which impact AHC.

In particular it now no longer strips the square brackets in IPv6 hosts
which are not tolerated by `inet_pton` so these must be manually
stripped.

swiftlang/swift-foundation#957
swiftlang/swift-foundation#958
swiftlang/swift-foundation#962
@jrflat
Copy link
Contributor

jrflat commented Oct 3, 2024

This is expected after updating URL to RFC 3986, which defines:

hier-part     = "//" authority path-abempty
authority     = [ userinfo "@" ] host [ ":" port ]

If a URL starts with // or contains // after a scheme, this implies that authority exists, which implies that host exists (but may be empty). This helps distinguish a URL with an authority and an empty host, from one where the host does not exist (such as in the URL string relative/path, where .host is nil). I see this was worked-around in AHC, but I'll keep an eye out for any more bincompat reports.

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

2 participants