Skip to content

Commit 02322ae

Browse files
committed
Used URI constructor that is escaping illegal characters.
Fixes #15
1 parent 9f63188 commit 02322ae

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/main/java/se/bjurr/violations/comments/bitbucketserver/lib/client/BitbucketServerInvoker.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.net.CookieManager;
1212
import java.net.CookiePolicy;
1313
import java.net.URI;
14+
import java.net.URL;
1415
import java.nio.charset.StandardCharsets;
1516
import java.util.Base64;
1617
import org.apache.http.HttpResponse;
@@ -104,7 +105,7 @@ private String doInvokeUrl(
104105
throw new IllegalArgumentException(
105106
"Unsupported http method:\n" + url + "\n" + method + "\n" + postContent);
106107
}
107-
request.setURI(new URI(url));
108+
request.setURI(convertToURIEscapingIllegalCharacters(url));
108109
final RequestConfig.Builder requestBuilder =
109110
RequestConfig.custom().setConnectionRequestTimeout(30000).setConnectTimeout(30000);
110111
request.setConfig(requestBuilder.build());
@@ -170,4 +171,10 @@ private String doInvokeUrl(
170171
}
171172
}
172173
}
174+
175+
private URI convertToURIEscapingIllegalCharacters(String string) throws Exception {
176+
URL url = new URL(string);
177+
URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef());
178+
return uri;
179+
}
173180
}

0 commit comments

Comments
 (0)