Fix wrong URL encoding in watcher HTTP client (#45894)

The test assumption was calling the wrong method resulting in a URL
encoding before returning the data.

Closes #44970
This commit is contained in:
Alexander Reelsen 2019-08-30 14:02:24 +02:00
parent 53f70ee996
commit 98c32c7846
2 changed files with 5 additions and 4 deletions

View File

@ -334,12 +334,13 @@ public class HttpClient implements Closeable {
String part = pathParts[i]; String part = pathParts[i];
boolean isLast = i == pathParts.length - 1; boolean isLast = i == pathParts.length - 1;
if (Strings.isEmpty(part) == false) { 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; boolean appendSlash = isPathEndsWithSlash && isLast;
if (appendSlash) { if (appendSlash) {
appendPart += "/"; unescapedPathParts.add("");
} }
unescapedPathParts.add(URLDecoder.decode(appendPart, StandardCharsets.UTF_8.name()));
} }
} }
} }

View File

@ -751,7 +751,7 @@ public class HttpClientTests extends ESTestCase {
private void assertCreateUri(String uri, String expectedPath) { private void assertCreateUri(String uri, String expectedPath) {
final HttpRequest request = HttpRequest.builder().fromUrl(uri).build(); final HttpRequest request = HttpRequest.builder().fromUrl(uri).build();
final Tuple<HttpHost, URI> tuple = HttpClient.createURI(request); final Tuple<HttpHost, URI> tuple = HttpClient.createURI(request);
assertThat(tuple.v2().getPath(), is(expectedPath)); assertThat(tuple.v2().getRawPath(), is(expectedPath));
} }
public static ClusterService mockClusterService() { public static ClusterService mockClusterService() {