Document IDs need to be URL decoded when indexed, closes #324.

This commit is contained in:
kimchy 2010-08-17 10:47:02 +03:00
parent c989d3a928
commit 7833cb1c76
2 changed files with 14 additions and 7 deletions

View File

@ -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);
}
}

View File

@ -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;
}
}