Skip to content
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

StringToCollectionConverter splits string by comma [SPR-15356] #19919

Closed
spring-projects-issues opened this issue Mar 17, 2017 · 5 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue

Comments

@spring-projects-issues
Copy link
Collaborator

None opened SPR-15356 and commented

When you submit a form (only tried post) with a parameter that includes a comma, and the parameter is bound to a List<String> then this value is passed through to the method org.springframework.core.convert.support.StringToCollectionConverter.convert(Object, TypeDescriptor, TypeDescriptor). That method then splits the String at the comma, resulting in a list with two elements instead of one.

I understand that comma is used to split array values in the url. I checked the raw request and the comma is translated to %2C so this shouldn't happen. It must be a bug somewhere in the call hierachy.

This problem only exists if one value is submitted for the list. If two or more values are submitted (e.g. two checkboxes checked) then a different converter is choosen (array to list) and no comma splitting is done.


Affects: 4.3.7

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

I checked the raw request and the comma is translated to %2C so this shouldn't happen.

Request parameter values from the ServletRequest are provided in decoded form so I'm not sure this has anything to do with it.

The description of the issue is insufficient. Could you provide an example of what the target Object and field(s) look like? Also the corresponding form fields and data.

@spring-projects-issues
Copy link
Collaborator Author

Sebastian Monte commented

I also run to this issue.

URL path:

/endpoint?param=1%2C2

In the controller I have a request parameter:

@RequestParam(value = "param", required = false) final Set<String> params

The "params" Set will include two values ("1" and "2"). I would expect the "params" set to contain one value "1,2" since the comma is escaped.

@spring-projects-issues spring-projects-issues added type: bug A general bug status: waiting-for-triage An issue we've not yet triaged or decided on in: core Issues in core modules (aop, beans, core, context, expression) and removed type: bug A general bug labels Jan 11, 2019
@RomainWilbert
Copy link

Same issue here...even if the comma is escaped (%2C) the string is split into 2 values :(

@rstoyanchev
Copy link
Contributor

This is actually a duplicate of #23820.

@rstoyanchev rstoyanchev added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 12, 2020
@rstoyanchev rstoyanchev self-assigned this Feb 12, 2020
@fy-kenny
Copy link

I redirect request parameters contains String arrays, but the dest request received one,two,... as only one param. how can i delimiter automatically. @rstoyanchev

Class Pojo {
List list;
}

redirectAttributes.addAllAttributes(request.getParameterMap());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

4 participants