-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Prevent duplicated encoding of setPath()
, stripPrefix()
in mvc
#3658
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -215,10 +215,12 @@ public static Function<ServerRequest, ServerRequest> removeRequestParameter(Stri | |
MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<>(request.params()); | ||
queryParams.remove(name); | ||
|
||
MultiValueMap<String, String> encodedQueryParams = UriUtils.encodeQueryParams(queryParams); | ||
|
||
// remove from uri | ||
URI newUri = UriComponentsBuilder.fromUri(request.uri()) | ||
.replaceQueryParams(unmodifiableMultiValueMap(queryParams)) | ||
.build() | ||
.replaceQueryParams(unmodifiableMultiValueMap(encodedQueryParams)) | ||
.build(true) | ||
.toUri(); | ||
|
||
// remove resolved params from request | ||
|
@@ -375,9 +377,11 @@ public static Function<ServerRequest, ServerRequest> setPath(String path) { | |
return request -> { | ||
Map<String, Object> uriVariables = MvcUtils.getUriTemplateVariables(request); | ||
URI uri = uriTemplate.expand(uriVariables); | ||
String newPath = uri.getRawPath(); | ||
|
||
URI prefixedUri = UriComponentsBuilder.fromUri(request.uri()).replacePath(newPath).build().toUri(); | ||
URI prefixedUri = UriComponentsBuilder.fromUri(request.uri()) | ||
.replacePath(uri.getRawPath()) | ||
.build(true) | ||
.toUri(); | ||
Comment on lines
+381
to
+384
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The modified path is already encoded, so no additional encoding will be applied. |
||
return ServerRequest.from(request).uri(prefixedUri).build(); | ||
}; | ||
} | ||
|
@@ -432,7 +436,7 @@ public static Function<ServerRequest, ServerRequest> stripPrefix(int parts) { | |
|
||
URI prefixedUri = UriComponentsBuilder.fromUri(request.uri()) | ||
.replacePath(newPath.toString()) | ||
.build() | ||
.build(true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The stripped path is already encoded, so no additional encoding will be applied. |
||
.toUri(); | ||
return ServerRequest.from(request).uri(prefixedUri).build(); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change only re-encodes request parameters, and does not affect other segments such as the request path.