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