@@ -1103,4 +1103,38 @@ final class URLTests : XCTestCase {
11031103 XCTAssertEqual ( urlComponents. string, nsURLComponents. string)
11041104 }
11051105#endif
1106+
1107+ func testURLComponentsUnixDomainSocketOverHTTPScheme( ) {
1108+ var comp = URLComponents ( )
1109+ comp. scheme = " http+unix "
1110+ comp. host = " /path/to/socket "
1111+ comp. path = " /info "
1112+ XCTAssertEqual ( comp. string, " http+unix://%2Fpath%2Fto%2Fsocket/info " )
1113+
1114+ comp. scheme = " https+unix "
1115+ XCTAssertEqual ( comp. string, " https+unix://%2Fpath%2Fto%2Fsocket/info " )
1116+
1117+ comp. encodedHost = " %2Fpath%2Fto%2Fsocket "
1118+ XCTAssertEqual ( comp. string, " https+unix://%2Fpath%2Fto%2Fsocket/info " )
1119+ XCTAssertEqual ( comp. encodedHost, " %2Fpath%2Fto%2Fsocket " )
1120+ XCTAssertEqual ( comp. host, " /path/to/socket " )
1121+ XCTAssertEqual ( comp. path, " /info " )
1122+
1123+ // "/path/to/socket" is not a valid host for schemes
1124+ // that IDNA-encode hosts instead of percent-encoding
1125+ comp. scheme = " http "
1126+ XCTAssertNil ( comp. string)
1127+
1128+ comp. scheme = " https "
1129+ XCTAssertNil ( comp. string)
1130+
1131+ comp. scheme = " https+unix "
1132+ XCTAssertEqual ( comp. string, " https+unix://%2Fpath%2Fto%2Fsocket/info " )
1133+
1134+ // Check that we can parse a percent-encoded http+unix URL string
1135+ comp = URLComponents ( string: " http+unix://%2Fpath%2Fto%2Fsocket/info " ) !
1136+ XCTAssertEqual ( comp. encodedHost, " %2Fpath%2Fto%2Fsocket " )
1137+ XCTAssertEqual ( comp. host, " /path/to/socket " )
1138+ XCTAssertEqual ( comp. path, " /info " )
1139+ }
11061140}
0 commit comments