-
Notifications
You must be signed in to change notification settings - Fork 470
UriBuilder query parameter encoding behaves differently depending on required RequestParameter #1565
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
Comments
Here's an additional comment from the gitter conversation that triggered this issue:
|
Seems to me it is actually a Spring hateoas issue since only required parameters are filtered https://github.com/spring-projects/spring-hateoas/blob/main/src/main/java/org/springframework/hateoas/UriTemplate.java#L262 |
You're right, this looks like a duplicate of #1485. I'm closing this issue for now, feel free to reopen it if Spring HATEOAS reporters find that the root cause belongs to Spring Framework. Thanks! |
Just a quick analysis. It looks like in Spring Framework, there's a conceptual difference between expanding a URI template and adding parameters via |
This should be fixed with the fix for #1485. Would you mind giving the 1.4 snapshots a try? |
@odrotbohm sure will try next week when I'm back at work |
@odrotbohm Tested on 1.4 snapshot and now the encoding is applied as expected. Thanks for looking into this. |
I'm upgrading from sb 1.5.9.RELEASE to 2.5.1 i steps and noticed a different behaviour in how the UriBuilder handles encoding of query parameters depending on if you set the RequestParam required to true or false.
The queryparamters ZonedDateTime has to be encoded (+sign), but is not if the RequestParam(required=false).
I would expect the parameter to be encoded no matter if it's required or not.
Running the example code will result in the first 'from' parameter to be encoded, but the 'to' not.
I think the issue lies in the DefaultUriBuilder or related. Spring Hateoas uses this to render links.
Following the link will result in ->
Resolved [org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.time.ZonedDateTime'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@org.springframework.web.bind.annotation.RequestParam @org.springframework.format.annotation.DateTimeFormat java.time.ZonedDateTime] for value '2021-06-18T14:59:05.802044 02:00[Europe/Copenhagen]'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2021-06-18T14:59:05.802044 02:00[Europe/Copenhagen]]]
Because + is treated as space.
Sample application ->
Setting both parameters to required = true renders the link correctly.
The text was updated successfully, but these errors were encountered: