Make RestUtils.decodeQueryString() more robust in edge cases
The code of decodeQueryString() had some trouble with weird URLs: (1) an input like "uri?param&p=v" causes an exception to be thrown (2) an input like "uri?param1¶m2" causes an infinite loop This could be verified against an ES server with requests like curl -XGET localhost:9200/test/_analyze?t&text=this+is+a+test # the exception stack trace shows up in logs curl -XGET localhost:9200/test/_analyze?t1&t2&text=this+is+a+test # never returns, never ends This change fixes these issues.
This commit is contained in:
parent
edb075b611
commit
154dcf007e
|
@ -39,10 +39,9 @@ public class RestUtils {
|
|||
int toIndex;
|
||||
while ((toIndex = queryString.indexOf('&', fromIndex)) >= 0) {
|
||||
int idx = queryString.indexOf('=', fromIndex);
|
||||
if (idx < 0) {
|
||||
continue;
|
||||
if (fromIndex < idx && idx < toIndex) {
|
||||
params.put(decodeComponent(queryString.substring(fromIndex, idx)), decodeComponent(queryString.substring(idx + 1, toIndex)));
|
||||
}
|
||||
params.put(decodeComponent(queryString.substring(fromIndex, idx)), decodeComponent(queryString.substring(idx + 1, toIndex)));
|
||||
fromIndex = toIndex + 1;
|
||||
}
|
||||
int idx = queryString.indexOf('=', fromIndex);
|
||||
|
|
Loading…
Reference in New Issue