Closed
Description
Initializing a URL from an IPv6 address in Swift 6 on Linux now does not strip enclosing square-brackets. In earlier Swift versions and on macOS the square-brackets are removed.
As well as being a behavior change this can cause issues when passing the host component on e.g. to inet_pton
which doesn't tolerate the square braces.
On Linux Swift 5.10:
1> import Foundation
2> let u = Foundation.URL(string: "http://[::1]")
[snip]
3> print(u!.host)
Optional("::1")
On Linux Swift 6.0.1:
1> import Foundation
2> let u = Foundation.URL(string: "http://[::1]")
[snip]
3> print(u!.host)
Optional("[::1]")
Metadata
Metadata
Assignees
Labels
No labels
Activity
workaround Foundation.URL behavior changes (#777)
jrflat commentedon Oct 3, 2024
This is expected from the update of
URL
to RFC 3986, which defines:with
host
including the[
and]
. We'd like to maintain this behavior for.host
, as it unifies the behaviors ofURL.host
,URL.host()
, andURLComponents.host
, but we'll keep an eye out if there's more bincompat issues from this change.YOCKOW commentedon Oct 11, 2024
Something about this that may impact existing code is discrepancy between macOS and Linux:
URL(string: "http://[::1]")!.host!
is "::1" (without square brackets) on macOS even in Swift 6.I think we'd better to resolve such discord at least.
Fix workaround for swiftlang/swift-foundation#957
URL.host
bracket stripping for compatibility #1008Confirm swiftlang/swift-foundation#957 is fixed.
Merge pull request #63 from YOCKOW/development