DATACMNS-692 - Fixed web parameter range handling for Pageables.

In case the PageableHandlerMethodArgumentResolver was configured to use one-indexed parameters, it wasn't defaulting the lower bounds for the page number. This caused indexes out of the allowed bound submitted causing an invalid index handed tor PageRequest. We now apply better range shifting before the bounds are applied.
This commit is contained in:
Oliver Gierke
2015-05-13 18:00:19 +02:00
parent 5405c6e2e7
commit 9230b5f30f
2 changed files with 25 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013 the original author or authors.
* Copyright 2013-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -236,6 +236,23 @@ public class PageableHandlerMethodArgumentResolverUnitTests extends PageableDefa
assertThat(result.getSort(), is(nullValue()));
}
/**
* @see DATACMNS-692
*/
@Test
public void oneIndexedParametersDefaultsIndexOutOfRange() {
PageableHandlerMethodArgumentResolver resolver = getResolver();
resolver.setOneIndexedParameters(true);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("page", "0");
Pageable result = resolver.resolveArgument(supportedMethodParameter, null, new ServletWebRequest(request), null);
assertThat(result.getPageNumber(), is(0));
}
@Override
protected PageableHandlerMethodArgumentResolver getResolver() {
PageableHandlerMethodArgumentResolver resolver = new PageableHandlerMethodArgumentResolver();