@@ -1137,4 +1137,38 @@ final class URLTests : XCTestCase {
1137
1137
XCTAssertEqual ( comp. host, " /path/to/socket " )
1138
1138
XCTAssertEqual ( comp. path, " /info " )
1139
1139
}
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
+ }
1140
1174
}
0 commit comments