Skip to content

Commit

Permalink
Fix wrong URL encoding in watcher HTTP client (#45894)
Browse files Browse the repository at this point in the history
The test assumption was calling the wrong method resulting in a URL
encoding before returning the data.

Closes #44970
  • Loading branch information
spinscale committed Aug 30, 2019
1 parent 5b2d4ad commit 35291f8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,13 @@ static Tuple<HttpHost, URI> createURI(HttpRequest request) {
String part = pathParts[i];
boolean isLast = i == pathParts.length - 1;
if (Strings.isEmpty(part) == false) {
String appendPart = part;
unescapedPathParts.add(URLDecoder.decode(part, StandardCharsets.UTF_8.name()));
// if the passed URL ends with a slash, adding an empty string to the
// unescaped paths will ensure the slash will be added back
boolean appendSlash = isPathEndsWithSlash && isLast;
if (appendSlash) {
appendPart += "/";
unescapedPathParts.add("");
}
unescapedPathParts.add(URLDecoder.decode(appendPart, StandardCharsets.UTF_8.name()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ public void testCreateUri() throws Exception {
private void assertCreateUri(String uri, String expectedPath) {
final HttpRequest request = HttpRequest.builder().fromUrl(uri).build();
final Tuple<HttpHost, URI> tuple = HttpClient.createURI(request);
assertThat(tuple.v2().getPath(), is(expectedPath));
assertThat(tuple.v2().getRawPath(), is(expectedPath));
}

public static ClusterService mockClusterService() {
Expand Down

0 comments on commit 35291f8

Please sign in to comment.