Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Sources/FoundationEssentials/URL/URLParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ internal struct RFC3986Parser: URLParserProtocol {
"addressbook",
"contact",
"phasset",
"http+unix",
"https+unix",
])

private static func looksLikeIPLiteral(_ host: some StringProtocol) -> Bool {
Expand Down
34 changes: 34 additions & 0 deletions Tests/FoundationEssentialsTests/URLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1031,4 +1031,38 @@ final class URLTests : XCTestCase {
XCTAssertEqual(comp.percentEncodedPath, "/my%00path")
XCTAssertEqual(comp.path, "/my\u{0}path")
}

func testURLComponentsUnixDomainSocketOverHTTPScheme() {
var comp = URLComponents()
comp.scheme = "http+unix"
comp.host = "/path/to/socket"
comp.path = "/info"
XCTAssertEqual(comp.string, "http+unix://%2Fpath%2Fto%2Fsocket/info")

comp.scheme = "https+unix"
XCTAssertEqual(comp.string, "https+unix://%2Fpath%2Fto%2Fsocket/info")

comp.encodedHost = "%2Fpath%2Fto%2Fsocket"
XCTAssertEqual(comp.string, "https+unix://%2Fpath%2Fto%2Fsocket/info")
XCTAssertEqual(comp.encodedHost, "%2Fpath%2Fto%2Fsocket")
XCTAssertEqual(comp.host, "/path/to/socket")
XCTAssertEqual(comp.path, "/info")

// "/path/to/socket" is not a valid host for schemes
// that IDNA-encode hosts instead of percent-encoding
comp.scheme = "http"
XCTAssertNil(comp.string)

comp.scheme = "https"
XCTAssertNil(comp.string)

comp.scheme = "https+unix"
XCTAssertEqual(comp.string, "https+unix://%2Fpath%2Fto%2Fsocket/info")

// Check that we can parse a percent-encoded http+unix URL string
comp = URLComponents(string: "http+unix://%2Fpath%2Fto%2Fsocket/info")!
XCTAssertEqual(comp.encodedHost, "%2Fpath%2Fto%2Fsocket")
XCTAssertEqual(comp.host, "/path/to/socket")
XCTAssertEqual(comp.path, "/info")
}
}