Skip to content

Commit e66fae5

Browse files
SNOW-1460355: Fix getHostFromServerUrl (snowflakedb#1779)
1 parent a79f58d commit e66fae5

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/main/java/net/snowflake/client/core/SFLoginInput.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,11 @@ static boolean getBooleanValue(Object v) {
426426
String getHostFromServerUrl() throws SFException {
427427
URL url;
428428
try {
429-
url = new URL(serverUrl);
429+
if (!serverUrl.startsWith("http")) {
430+
url = new URL("https://" + serverUrl);
431+
} else {
432+
url = new URL(serverUrl);
433+
}
430434
} catch (MalformedURLException e) {
431435
throw new SFException(
432436
e, ErrorCode.INTERNAL_ERROR, "Invalid serverUrl for retrieving host name");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package net.snowflake.client.core;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import org.junit.Test;
6+
7+
public class SFLoginInputTest {
8+
9+
@Test
10+
public void testGetHostFromServerUrlWithoutProtocolShouldNotThrow() throws SFException {
11+
SFLoginInput sfLoginInput = new SFLoginInput();
12+
sfLoginInput.setServerUrl("host.com:443");
13+
assertEquals("host.com", sfLoginInput.getHostFromServerUrl());
14+
}
15+
16+
@Test
17+
public void testGetHostFromServerUrlWithProtocolShouldNotThrow() throws SFException {
18+
SFLoginInput sfLoginInput = new SFLoginInput();
19+
sfLoginInput.setServerUrl("https://host.com");
20+
assertEquals("host.com", sfLoginInput.getHostFromServerUrl());
21+
}
22+
}

0 commit comments

Comments
 (0)