diff --git a/slack-api-client/src/main/java/com/slack/api/util/http/ProxyUrlUtil.java b/slack-api-client/src/main/java/com/slack/api/util/http/ProxyUrlUtil.java index c5be5343a..308c18d6c 100644 --- a/slack-api-client/src/main/java/com/slack/api/util/http/ProxyUrlUtil.java +++ b/slack-api-client/src/main/java/com/slack/api/util/http/ProxyUrlUtil.java @@ -34,8 +34,9 @@ public static ProxyUrl parse(String proxyUrl) { return null; } String[] proxyUrlElements = proxyUrl.split("://"); - String schema = proxyUrlElements[0] + "://"; - String urlWithoutSchema = proxyUrlElements[1]; + boolean withSchema = proxyUrlElements.length == 2; + String schema = withSchema ? proxyUrlElements[0] + "://" : "http://"; + String urlWithoutSchema = withSchema ? proxyUrlElements[1] : proxyUrlElements[0]; String[] urlWithUserAndPasswordIfTwoElements = urlWithoutSchema.split("@"); if (urlWithUserAndPasswordIfTwoElements.length == 2) { String[] userAndPassword = urlWithUserAndPasswordIfTwoElements[0].split(":"); @@ -51,7 +52,7 @@ public static ProxyUrl parse(String proxyUrl) { .port(hostAndPort.length == 2 ? Integer.parseInt(hostAndPort[1].replace("/", "")) : 80) .build(); } else { - String[] hostAndPort = proxyUrl.split("://")[1].split(":"); + String[] hostAndPort = (withSchema ? proxyUrlElements[1] : proxyUrlElements[0]).split(":"); return ProxyUrl.builder() .schema(schema) .host(hostAndPort[0]) diff --git a/slack-api-client/src/test/java/test_locally/api/util/http/ProxyUrlUtilTest.java b/slack-api-client/src/test/java/test_locally/api/util/http/ProxyUrlUtilTest.java index ead1eb425..e3fa51f6d 100644 --- a/slack-api-client/src/test/java/test_locally/api/util/http/ProxyUrlUtilTest.java +++ b/slack-api-client/src/test/java/test_locally/api/util/http/ProxyUrlUtilTest.java @@ -51,4 +51,26 @@ public void parse_username_password() { public void parse_invalid_format() { ProxyUrlUtil.parse("http://foo:bar:baz@localhost:9000"); } + + @Test + public void parse_no_schema() { + ProxyUrlUtil.ProxyUrl expected = ProxyUrlUtil.ProxyUrl.builder() + .schema("http://") + .host("localhost") + .port(9000) + .build(); + assertThat(ProxyUrlUtil.parse("localhost:9000"), is(expected)); + } + + @Test + public void parse_username_password_no_schema() { + ProxyUrlUtil.ProxyUrl expected = ProxyUrlUtil.ProxyUrl.builder() + .schema("http://") + .host("localhost") + .username("user") + .password("password") + .port(9000) + .build(); + assertThat(ProxyUrlUtil.parse("user:password@localhost:9000"), is(expected)); + } }