Merge pull request #13545 from izeye:fix-traceable-query-string

* pr/13545:
  Fix query string encoding in TraceableHttpServletRequest
This commit is contained in:
Stephane Nicoll 2018-07-10 15:58:26 +02:00
commit dd2b0eb739
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()); return new URI(urlBuffer.toString());
} }
catch (URISyntaxException ex) { catch (URISyntaxException ex) {
String encoded = UriUtils.encode(queryString, StandardCharsets.UTF_8); String encoded = UriUtils.encodeQuery(queryString, StandardCharsets.UTF_8);
StringBuffer urlBuffer = appendQueryString(encoded); StringBuffer urlBuffer = appendQueryString(encoded);
return URI.create(urlBuffer.toString()); return URI.create(urlBuffer.toString());
} }
} }
private StringBuffer appendQueryString(String queryString) { private StringBuffer appendQueryString(String queryString) {
StringBuffer urlBuffer = this.request.getRequestURL(); return this.request.getRequestURL().append("?").append(queryString);
urlBuffer.append("?");
urlBuffer.append(queryString);
return urlBuffer;
} }
@Override @Override

View File

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