Skip to content

Commit d7be92b

Browse files
authored
(135926523) URLComponents: support ws(s)+unix schemes (#918)
1 parent e5cff55 commit d7be92b

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

Sources/FoundationEssentials/URL/URLParser.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ internal struct RFC3986Parser: URLParserProtocol {
224224
"phasset",
225225
"http+unix",
226226
"https+unix",
227+
"ws+unix",
228+
"wss+unix",
227229
])
228230

229231
private static func looksLikeIPLiteral(_ host: some StringProtocol) -> Bool {

Tests/FoundationEssentialsTests/URLTests.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,4 +1137,38 @@ final class URLTests : XCTestCase {
11371137
XCTAssertEqual(comp.host, "/path/to/socket")
11381138
XCTAssertEqual(comp.path, "/info")
11391139
}
1140+
1141+
func testURLComponentsUnixDomainSocketOverWebSocketScheme() {
1142+
var comp = URLComponents()
1143+
comp.scheme = "ws+unix"
1144+
comp.host = "/path/to/socket"
1145+
comp.path = "/info"
1146+
XCTAssertEqual(comp.string, "ws+unix://%2Fpath%2Fto%2Fsocket/info")
1147+
1148+
comp.scheme = "wss+unix"
1149+
XCTAssertEqual(comp.string, "wss+unix://%2Fpath%2Fto%2Fsocket/info")
1150+
1151+
comp.encodedHost = "%2Fpath%2Fto%2Fsocket"
1152+
XCTAssertEqual(comp.string, "wss+unix://%2Fpath%2Fto%2Fsocket/info")
1153+
XCTAssertEqual(comp.encodedHost, "%2Fpath%2Fto%2Fsocket")
1154+
XCTAssertEqual(comp.host, "/path/to/socket")
1155+
XCTAssertEqual(comp.path, "/info")
1156+
1157+
// "/path/to/socket" is not a valid host for schemes
1158+
// that IDNA-encode hosts instead of percent-encoding
1159+
comp.scheme = "ws"
1160+
XCTAssertNil(comp.string)
1161+
1162+
comp.scheme = "wss"
1163+
XCTAssertNil(comp.string)
1164+
1165+
comp.scheme = "wss+unix"
1166+
XCTAssertEqual(comp.string, "wss+unix://%2Fpath%2Fto%2Fsocket/info")
1167+
1168+
// Check that we can parse a percent-encoded ws+unix URL string
1169+
comp = URLComponents(string: "ws+unix://%2Fpath%2Fto%2Fsocket/info")!
1170+
XCTAssertEqual(comp.encodedHost, "%2Fpath%2Fto%2Fsocket")
1171+
XCTAssertEqual(comp.host, "/path/to/socket")
1172+
XCTAssertEqual(comp.path, "/info")
1173+
}
11401174
}

0 commit comments

Comments
 (0)