@@ -1031,4 +1031,38 @@ final class URLTests : XCTestCase {
10311031 XCTAssertEqual ( comp. percentEncodedPath, " /my%00path " )
10321032 XCTAssertEqual ( comp. path, " /my \u{0} path " )
10331033 }
1034+
1035+ func testURLComponentsUnixDomainSocketOverHTTPScheme( ) {
1036+ var comp = URLComponents ( )
1037+ comp. scheme = " http+unix "
1038+ comp. host = " /path/to/socket "
1039+ comp. path = " /info "
1040+ XCTAssertEqual ( comp. string, " http+unix://%2Fpath%2Fto%2Fsocket/info " )
1041+
1042+ comp. scheme = " https+unix "
1043+ XCTAssertEqual ( comp. string, " https+unix://%2Fpath%2Fto%2Fsocket/info " )
1044+
1045+ comp. encodedHost = " %2Fpath%2Fto%2Fsocket "
1046+ XCTAssertEqual ( comp. string, " https+unix://%2Fpath%2Fto%2Fsocket/info " )
1047+ XCTAssertEqual ( comp. encodedHost, " %2Fpath%2Fto%2Fsocket " )
1048+ XCTAssertEqual ( comp. host, " /path/to/socket " )
1049+ XCTAssertEqual ( comp. path, " /info " )
1050+
1051+ // "/path/to/socket" is not a valid host for schemes
1052+ // that IDNA-encode hosts instead of percent-encoding
1053+ comp. scheme = " http "
1054+ XCTAssertNil ( comp. string)
1055+
1056+ comp. scheme = " https "
1057+ XCTAssertNil ( comp. string)
1058+
1059+ comp. scheme = " https+unix "
1060+ XCTAssertEqual ( comp. string, " https+unix://%2Fpath%2Fto%2Fsocket/info " )
1061+
1062+ // Check that we can parse a percent-encoded http+unix URL string
1063+ comp = URLComponents ( string: " http+unix://%2Fpath%2Fto%2Fsocket/info " ) !
1064+ XCTAssertEqual ( comp. encodedHost, " %2Fpath%2Fto%2Fsocket " )
1065+ XCTAssertEqual ( comp. host, " /path/to/socket " )
1066+ XCTAssertEqual ( comp. path, " /info " )
1067+ }
10341068}
0 commit comments