Skip to content

TraceableHttpServletRequest encodes query strings incorrectly #13545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,14 @@ public URI getUri() {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ public void getUriShouldReturnUriWithQueryString() {
@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) {
Expand Down