Adapt SortHandlerMethodArgumentResolver after changes to sort parameter.
Since the introduction of 6e22ffd, the sort parameter has been rendered as composite parameter which will cause the comma used to delimit property from direction potentially be encoded by clients following the URI template RFC. Thus, we need to defensively decode the source parameter value before parsing.
Related ticket: GH-2531.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.web;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
@@ -23,8 +24,8 @@ import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.support.WebDataBinderFactory;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||
import org.springframework.web.util.UriUtils;
|
||||
|
||||
/**
|
||||
* {@link HandlerMethodArgumentResolver} to automatically create {@link Sort} instances from request parameters or
|
||||
@@ -61,6 +62,10 @@ public class SortHandlerMethodArgumentResolver extends SortHandlerMethodArgument
|
||||
return getDefaultFromAnnotationOrFallback(parameter);
|
||||
}
|
||||
|
||||
return parseParameterIntoSort(Arrays.asList(directionParameter), getPropertyDelimiter());
|
||||
var decoded = Arrays.stream(directionParameter)
|
||||
.map(it -> UriUtils.decode(it, StandardCharsets.UTF_8))
|
||||
.toList();
|
||||
|
||||
return parseParameterIntoSort(decoded, getPropertyDelimiter());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user