DATACMNS-1551 - SortHandlerMethodArgumentResolver now drops dot-only property segments.

If plain dots were submitted as elements in a Sort expression to be parsed by SortHandlerMethodArgumentResolver, those dots would be considered a property of the sort expression, which is of course wrong. We now drop property candidates solely consisting of dots and whitespace.
This commit is contained in:
Oliver Drotbohm
2019-07-01 14:04:10 +02:00
parent bf1e00e93f
commit 4c1aed27d6
2 changed files with 30 additions and 1 deletions

View File

@@ -18,6 +18,8 @@ package org.springframework.data.web;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.domain.Sort.Direction.*;
import java.util.stream.Stream;
import javax.servlet.http.HttpServletRequest;
import org.junit.BeforeClass;
@@ -182,6 +184,20 @@ public class SortHandlerMethodArgumentResolverUnitTests extends SortDefaultUnitT
assertThat(resolveSort(request, getParameterOfMethod("containeredDefault"))).isEqualTo(Sort.by("foo", "bar"));
}
@Test // DATACMNS-1551
public void resolvesDotOnlyInputToDefault() {
Stream.of(".", ".,ASC").forEach(it -> {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("sort", it);
assertThatCode(() -> {
assertThat(resolveSort(request, PARAMETER)).isEqualTo(Sort.unsorted());
}).doesNotThrowAnyException();
});
}
private static Sort resolveSort(HttpServletRequest request, MethodParameter parameter) throws Exception {
SortHandlerMethodArgumentResolver resolver = new SortHandlerMethodArgumentResolver();