diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/common/http/HttpClient.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/common/http/HttpClient.java index 99945c09375..49e27f51ea7 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/common/http/HttpClient.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/common/http/HttpClient.java @@ -334,12 +334,13 @@ public class HttpClient implements Closeable { 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())); } } } diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/common/http/HttpClientTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/common/http/HttpClientTests.java index 1f8ec6bb5d8..75e551b58e5 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/common/http/HttpClientTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/common/http/HttpClientTests.java @@ -751,7 +751,7 @@ public class HttpClientTests extends ESTestCase { private void assertCreateUri(String uri, String expectedPath) { final HttpRequest request = HttpRequest.builder().fromUrl(uri).build(); final Tuple tuple = HttpClient.createURI(request); - assertThat(tuple.v2().getPath(), is(expectedPath)); + assertThat(tuple.v2().getRawPath(), is(expectedPath)); } public static ClusterService mockClusterService() {