diff --git a/src/main/java/org/springframework/data/web/SortHandlerMethodArgumentResolverSupport.java b/src/main/java/org/springframework/data/web/SortHandlerMethodArgumentResolverSupport.java index 422bb297e..3c5ecb237 100644 --- a/src/main/java/org/springframework/data/web/SortHandlerMethodArgumentResolverSupport.java +++ b/src/main/java/org/springframework/data/web/SortHandlerMethodArgumentResolverSupport.java @@ -187,8 +187,10 @@ public abstract class SortHandlerMethodArgumentResolverSupport { /** * Parses the given sort expressions into a {@link Sort} instance. The implementation expects the sources to be a - * concatenation of Strings using the given delimiter. If the last element can be parsed into a {@link Direction} it's - * considered a {@link Direction} and a simple property otherwise. + * concatenation of Strings using the given delimiter. If the last element is equal to "ignorecase" (when using a + * case-insensitive comparison), the sort order will be performed without respect to case. If the last element (or the + * penultimate element if the last is "ignorecase") can be parsed into a {@link Direction} it's considered a + * {@link Direction} and a simple property otherwise. * * @param source will never be {@literal null}. * @param delimiter the delimiter to be used to split up the source elements, will never be {@literal null}. diff --git a/src/test/java/org/springframework/data/web/SortHandlerMethodArgumentResolverUnitTests.java b/src/test/java/org/springframework/data/web/SortHandlerMethodArgumentResolverUnitTests.java index dc29316ce..1bd12455a 100755 --- a/src/test/java/org/springframework/data/web/SortHandlerMethodArgumentResolverUnitTests.java +++ b/src/test/java/org/springframework/data/web/SortHandlerMethodArgumentResolverUnitTests.java @@ -18,6 +18,7 @@ package org.springframework.data.web; import static org.assertj.core.api.Assertions.*; import static org.springframework.data.domain.Sort.Direction.*; +import java.util.Arrays; import java.util.stream.Stream; import javax.servlet.http.HttpServletRequest; @@ -74,6 +75,28 @@ public class SortHandlerMethodArgumentResolverUnitTests extends SortDefaultUnitT assertThat(sort.isSorted()).isFalse(); } + @Test + public void sortParamHandlesSortOrderAndIgnoreCase() throws Exception { + + MockHttpServletRequest request = new MockHttpServletRequest(); + request.addParameter("sort", "property,DESC,IgnoreCase"); + request.addParameter("sort", ""); + + assertThat(resolveSort(request, PARAMETER)) + .isEqualTo(Sort.by(Arrays.asList(new Order(DESC, "property").ignoreCase()))); + } + + @Test + public void sortParamHandlesIgnoreCase() throws Exception { + + MockHttpServletRequest request = new MockHttpServletRequest(); + request.addParameter("sort", "property,IgnoreCase"); + request.addParameter("sort", ""); + + assertThat(resolveSort(request, PARAMETER)) + .isEqualTo(Sort.by(Arrays.asList(new Order(ASC, "property").ignoreCase()))); + } + @Test public void discoversSimpleSortFromRequest() {