diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/http/netty/NettyHttpRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/http/netty/NettyHttpRequest.java index 9bb5cb270b1..0fd666e7a18 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/http/netty/NettyHttpRequest.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/http/netty/NettyHttpRequest.java @@ -51,9 +51,9 @@ public class NettyHttpRequest extends AbstractRestRequest implements HttpRequest String uri = request.getUri(); int pathEndPos = uri.indexOf('?'); if (pathEndPos < 0) { - this.path = uri; + this.path = RestUtils.decodeComponent(uri); } else { - this.path = uri.substring(0, pathEndPos); + this.path = RestUtils.decodeComponent(uri.substring(0, pathEndPos)); RestUtils.decodeQueryString(uri, pathEndPos + 1, params); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/support/RestUtils.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/support/RestUtils.java index 23f9aa966a0..028465eaa43 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/support/RestUtils.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/support/RestUtils.java @@ -52,14 +52,21 @@ public class RestUtils { params.put(decodeComponent(queryString.substring(fromIndex, idx)), decodeComponent(queryString.substring(idx + 1))); } - private static String decodeComponent(String s) { + public static String decodeComponent(String s) { if (s == null) { return ""; } - try { - return URLDecoder.decode(s, "UTF8"); - } catch (UnsupportedEncodingException e) { - throw new UnsupportedCharsetException("UTF8"); + int numChars = s.length(); + for (int i = 0; i < numChars; i++) { + // do an initial check if it requires decoding do it and return + if (s.charAt(i) == '+' || s.charAt(i) == '%') { + try { + return URLDecoder.decode(s, "UTF8"); + } catch (UnsupportedEncodingException e) { + throw new UnsupportedCharsetException("UTF8"); + } + } } + return s; } }