File tree Expand file tree Collapse file tree 2 files changed +26
-3
lines changed
main/java/com/slack/api/util/http
test/java/test_locally/api/util/http Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -34,8 +34,9 @@ public static ProxyUrl parse(String proxyUrl) {
3434 return null ;
3535 }
3636 String [] proxyUrlElements = proxyUrl .split ("://" );
37- String schema = proxyUrlElements [0 ] + "://" ;
38- String urlWithoutSchema = proxyUrlElements [1 ];
37+ boolean withSchema = proxyUrlElements .length == 2 ;
38+ String schema = withSchema ? proxyUrlElements [0 ] + "://" : "http://" ;
39+ String urlWithoutSchema = withSchema ? proxyUrlElements [1 ] : proxyUrlElements [0 ];
3940 String [] urlWithUserAndPasswordIfTwoElements = urlWithoutSchema .split ("@" );
4041 if (urlWithUserAndPasswordIfTwoElements .length == 2 ) {
4142 String [] userAndPassword = urlWithUserAndPasswordIfTwoElements [0 ].split (":" );
@@ -51,7 +52,7 @@ public static ProxyUrl parse(String proxyUrl) {
5152 .port (hostAndPort .length == 2 ? Integer .parseInt (hostAndPort [1 ].replace ("/" , "" )) : 80 )
5253 .build ();
5354 } else {
54- String [] hostAndPort = proxyUrl . split ( "://" ) [1 ].split (":" );
55+ String [] hostAndPort = ( withSchema ? proxyUrlElements [1 ] : proxyUrlElements [ 0 ]) .split (":" );
5556 return ProxyUrl .builder ()
5657 .schema (schema )
5758 .host (hostAndPort [0 ])
Original file line number Diff line number Diff line change @@ -51,4 +51,26 @@ public void parse_username_password() {
5151 public void parse_invalid_format () {
5252 ProxyUrlUtil .parse ("http://foo:bar:baz@localhost:9000" );
5353 }
54+
55+ @ Test
56+ public void parse_no_schema () {
57+ ProxyUrlUtil .ProxyUrl expected = ProxyUrlUtil .ProxyUrl .builder ()
58+ .schema ("http://" )
59+ .host ("localhost" )
60+ .port (9000 )
61+ .build ();
62+ assertThat (ProxyUrlUtil .parse ("localhost:9000" ), is (expected ));
63+ }
64+
65+ @ Test
66+ public void parse_username_password_no_schema () {
67+ ProxyUrlUtil .ProxyUrl expected = ProxyUrlUtil .ProxyUrl .builder ()
68+ .schema ("http://" )
69+ .host ("localhost" )
70+ .username ("user" )
71+ .password ("password" )
72+ .port (9000 )
73+ .build ();
74+ assertThat (ProxyUrlUtil .parse ("user:password@localhost:9000" ), is (expected ));
75+ }
5476}
You can’t perform that action at this time.
0 commit comments