Skip to content

Commit dd2b0eb

Browse files
committed
Merge pull request #13545 from izeye:fix-traceable-query-string
* pr/13545: Fix query string encoding in TraceableHttpServletRequest
2 parents 419bf0d + 46e6aa5 commit dd2b0eb

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/trace/servlet/TraceableHttpServletRequest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,14 @@ public URI getUri() {
6060
return new URI(urlBuffer.toString());
6161
}
6262
catch (URISyntaxException ex) {
63-
String encoded = UriUtils.encode(queryString, StandardCharsets.UTF_8);
63+
String encoded = UriUtils.encodeQuery(queryString, StandardCharsets.UTF_8);
6464
StringBuffer urlBuffer = appendQueryString(encoded);
6565
return URI.create(urlBuffer.toString());
6666
}
6767
}
6868

6969
private StringBuffer appendQueryString(String queryString) {
70-
StringBuffer urlBuffer = this.request.getRequestURL();
71-
urlBuffer.append("?");
72-
urlBuffer.append(queryString);
73-
return urlBuffer;
70+
return this.request.getRequestURL().append("?").append(queryString);
7471
}
7572

7673
@Override

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/web/trace/servlet/TraceableHttpServletRequestTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ public void getUriShouldReturnUriWithQueryString() {
5050
@Test
5151
public void getUriWithSpecialCharactersInQueryStringShouldEncode() {
5252
this.request.setQueryString("a=${b}");
53-
validate("http://localhost/script?a%3D%24%7Bb%7D");
53+
validate("http://localhost/script?a=$%7Bb%7D");
5454
}
5555

5656
@Test
5757
public void getUriWithSpecialCharactersEncodedShouldNotDoubleEncode() {
58-
this.request.setQueryString("a%3D%24%7Bb%7D");
59-
validate("http://localhost/script?a%3D%24%7Bb%7D");
58+
this.request.setQueryString("a=$%7Bb%7D");
59+
validate("http://localhost/script?a=$%7Bb%7D");
6060
}
6161

6262
private void validate(String expectedUri) {

0 commit comments

Comments
 (0)