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
Add option to encode MultiValueMap of query params #24043
Comments
Current workaround: RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
HttpServletRequest servletRequest = ((ServletRequestAttributes) attributes).getRequest();
WebRequest webRequest = new ServletWebRequest(servletRequest);
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
for (Map.Entry<String, String[]> e : webRequest.getParameterMap().entrySet()) {
params.addAll(e.getKey(), Arrays.asList(e.getValue()));
}
ServletUriComponentsBuilder.fromRequest(servletRequest).replaceQueryParams(params) There might be a better way to get the |
The Javadoc for for So this is expected behavior. We could improve the Javadoc on |
The greater problem comes when you then use that builder to e.g. add another parameter that will need encoding. It would be better IMO to always create builders with their source parts decoded. |
I see your point but there is ambiguity once a URI component (e.g. path, query) is decoded. For example Regardless, we can't change how Currently there is a method to encode individual query params or a query string. We can add an additional one to encode from a MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
// add params
ServletUriComponentsBuilder.fromCurrentRequest()
.queryParams(UriUtils.encodeQueryParams(params))
.build(true)
.toUriString(); |
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
@rstoyanchev what feedback are you waiting for? |
I guess the issue bot doesn't react to emojis :), thanks. |
Parameters passed using %-encoding will be double escaped by
fromCurrentRequest()
:Spring Web 5.2.1.RELEASE
The text was updated successfully, but these errors were encountered: