-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Provide mechanism to control trimming in StringToArrayConverter and StringToCollectionConverter #23850
Comments
We can't really change the default behavior in web applications. Regardless of one's opinion (and from prior discussions, something like this will have opinions on both sides) existing applications already rely on the current behavior. Adding a trim property to those converters however does seem reasonable to me. |
This applies to |
I think it's reasonable to add opt-in trimming support (enabled by default, of course) to those converters, especially since they would then align with the existing ... except that those two classes are not |
Ah, so they are. That makes the question even more pertinent. How is one even supposed to control this? In a web application it is possible to register a |
In the web, if you're only concerned with converting from a If we make Otherwise, users would have to implement their own variants of To be honest, I've never understood why |
Team Decisions: Investigate how to make the trimming in such converters configurable without making such converters Alternatively, we may decide to make certain built-in converters directly We may consider introducing a If we make the trimming support configurable, we would need to assess how best to apply that to existing default registered converters — for an entire If we extract the existing core functionality from In any case, we must keep in mind that |
@RequestParams
(i.e. HTTP query parameters) with leading or trailing spaces, including single parameters or delimited parameters, are trimmed when mapping them to a collection. It is likely this happens for other cases. A query parameter with a leading/trailing space is a perfectly reasonable construct provided it is encoded correctly. However by the time it gets into a controller, the space(s) have been trimmed.I can see this happening in at least two Boot classes, and there are probably more:
StringToCollectionConverter
DelimitedStringToCollectionConverter
Simply removing the
trim()
calls is not the right choice as these are also used for parsingapplication.yml
, and possibly have other uses. I suggest these converters should accept a trim? parameter at construction time, and theWebConversionService
be given its own instances of the converters withtrim=false
so query params with leading/trailing spaces can be properly passed. Something like that anyway...The text was updated successfully, but these errors were encountered: