-
Notifications
You must be signed in to change notification settings - Fork 38.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
GET query parameters containing comma are not properly URL decoded #29411
Comments
Probably in the same functional area, spaces ( |
The way I see it, at a very high level, the parameter resolution needs to be processed in 2 rather distinct initial stages:
That way commas, equal signs & ampersands encoded into the values (stage 2) are not mixed with the ones that are actually part of the URL syntax (stage 1). Obviously, further processing will take place after these initial steps, e.g. data conversion. |
Potential duplicate of: |
Looks like it. Thanks for pointing that out! |
Thanks for raising the issue, and indeed that is how the framework gets better. I'm afraid in this case there isn't much we can do. For once the At best it would need to be a different annotation, but we will not introduce one just for this. The recommendations under #23820, although you may see them as a workaround, do provide flexibility around how this should be handled, and that is probably the best option in this case. You could also create your own custom argument resolver. |
Well, something as simple as: Index: spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java
--- a/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java (revision 5ea8ba1b96084792a802cf7eef1ef176f53efe8d)
+++ b/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java (date 1675861396950)
@@ -180,7 +180,11 @@
if (arg == null) {
String[] paramValues = request.getParameterValues(name);
if (paramValues != null) {
- arg = (paramValues.length == 1 ? paramValues[0] : paramValues);
+ if (Collection.class.isAssignableFrom(parameter.getParameterType())) {
+ arg = paramValues;
+ } else {
+ arg = (paramValues.length == 1 ? paramValues[0] : paramValues);
+ }
}
}
return arg; could potentially sort out the encoded comma issue, depending on how the underlying |
Affects: Spring Boot 2.7.5
Hello,
I recently realised that one of my
GET
endpoints has issues if the values passed in the query params contain commas (,
).Basically, I expect to be able to embed a comma into a single value being passed into a query param, however, the receiving end must define the data type as
List<String>
& Spring splits the value into 2 rather than keeping it in one piece.To give an example, assume you have this endpoint:
If you hit it with this request:
curl http://localhost:8080/test?res=xx%2Cyy
then you get back
["xx","yy"]
, which is exactly the same result as requestingcurl http://localhost:8080/test?res=xx,yy
, but I expect to get back a list with a single element instead,["xx,yy"]
.Demo app can be found here.
Thank you very much!
The text was updated successfully, but these errors were encountered: