Fix query string encoding in TraceableHttpServletRequest

Closes gh-13545
This commit is contained in:
Johnny Lim
2018-06-22 01:58:58 +09:00
committed by Stephane Nicoll
parent 419bf0d1ed
commit 46e6aa5963
2 changed files with 5 additions and 8 deletions

View File

@@ -60,17 +60,14 @@ final class TraceableHttpServletRequest implements TraceableRequest {
return new URI(urlBuffer.toString());
}
catch (URISyntaxException ex) {
String encoded = UriUtils.encode(queryString, StandardCharsets.UTF_8);
String encoded = UriUtils.encodeQuery(queryString, StandardCharsets.UTF_8);
StringBuffer urlBuffer = appendQueryString(encoded);
return URI.create(urlBuffer.toString());
}
}
private StringBuffer appendQueryString(String queryString) {
StringBuffer urlBuffer = this.request.getRequestURL();
urlBuffer.append("?");
urlBuffer.append(queryString);
return urlBuffer;
return this.request.getRequestURL().append("?").append(queryString);
}
@Override

View File

@@ -50,13 +50,13 @@ public class TraceableHttpServletRequestTests {
@Test
public void getUriWithSpecialCharactersInQueryStringShouldEncode() {
this.request.setQueryString("a=${b}");
validate("http://localhost/script?a%3D%24%7Bb%7D");
validate("http://localhost/script?a=$%7Bb%7D");
}
@Test
public void getUriWithSpecialCharactersEncodedShouldNotDoubleEncode() {
this.request.setQueryString("a%3D%24%7Bb%7D");
validate("http://localhost/script?a%3D%24%7Bb%7D");
this.request.setQueryString("a=$%7Bb%7D");
validate("http://localhost/script?a=$%7Bb%7D");
}
private void validate(String expectedUri) {