@@ -1082,4 +1082,38 @@ final class URLTests : XCTestCase {
1082
1082
XCTAssertEqual ( comp. percentEncodedPath, " /my%00path " )
1083
1083
XCTAssertEqual ( comp. path, " /my \u{0} path " )
1084
1084
}
1085
+
1086
+ func testURLComponentsUnixDomainSocketOverHTTPScheme( ) {
1087
+ var comp = URLComponents ( )
1088
+ comp. scheme = " http+unix "
1089
+ comp. host = " /path/to/socket "
1090
+ comp. path = " /info "
1091
+ XCTAssertEqual ( comp. string, " http+unix://%2Fpath%2Fto%2Fsocket/info " )
1092
+
1093
+ comp. scheme = " https+unix "
1094
+ XCTAssertEqual ( comp. string, " https+unix://%2Fpath%2Fto%2Fsocket/info " )
1095
+
1096
+ comp. encodedHost = " %2Fpath%2Fto%2Fsocket "
1097
+ XCTAssertEqual ( comp. string, " https+unix://%2Fpath%2Fto%2Fsocket/info " )
1098
+ XCTAssertEqual ( comp. encodedHost, " %2Fpath%2Fto%2Fsocket " )
1099
+ XCTAssertEqual ( comp. host, " /path/to/socket " )
1100
+ XCTAssertEqual ( comp. path, " /info " )
1101
+
1102
+ // "/path/to/socket" is not a valid host for schemes
1103
+ // that IDNA-encode hosts instead of percent-encoding
1104
+ comp. scheme = " http "
1105
+ XCTAssertNil ( comp. string)
1106
+
1107
+ comp. scheme = " https "
1108
+ XCTAssertNil ( comp. string)
1109
+
1110
+ comp. scheme = " https+unix "
1111
+ XCTAssertEqual ( comp. string, " https+unix://%2Fpath%2Fto%2Fsocket/info " )
1112
+
1113
+ // Check that we can parse a percent-encoded http+unix URL string
1114
+ comp = URLComponents ( string: " http+unix://%2Fpath%2Fto%2Fsocket/info " ) !
1115
+ XCTAssertEqual ( comp. encodedHost, " %2Fpath%2Fto%2Fsocket " )
1116
+ XCTAssertEqual ( comp. host, " /path/to/socket " )
1117
+ XCTAssertEqual ( comp. path, " /info " )
1118
+ }
1085
1119
}
0 commit comments