Merge pull request #13545 from izeye:fix-traceable-query-string
* pr/13545: Fix query string encoding in TraceableHttpServletRequest
This commit is contained in:
commit
dd2b0eb739
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue