[OLINGO-1117] Sending skip and take requests without a value returns String index out of range Exception

This commit is contained in:
ramya vasanth 2017-06-21 14:01:05 +05:30
parent 8f1a079faf
commit 891421d7fc
2 changed files with 28 additions and 1 deletions

View File

@ -181,5 +181,29 @@ public class BasicHttpITCase extends AbstractBaseTestITCase {
protected ODataClient getClient() {
return null;
}
@Test
public void testInvalidTopUrl() throws Exception {
URL url = new URL(SERVICE_URI + "?$top");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod(HttpMethod.GET.name());
connection.connect();
assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), connection.getResponseCode());
assertTrue(IOUtils.toString(connection.getErrorStream()).
contains("The system query option '$top' has the not-allowed value ''."));
}
@Test
public void testInvalidSkipUrl() throws Exception {
URL url = new URL(SERVICE_URI + "?$skip=");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod(HttpMethod.GET.name());
connection.connect();
assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), connection.getResponseCode());
assertTrue(IOUtils.toString(connection.getErrorStream()).
contains("The system query option '$skip' has the not-allowed value ''."));
}
}

View File

@ -211,7 +211,10 @@ public class ODataHandlerImpl implements ODataHandler {
if(endIndex == -1) {
endIndex = query.length();
}
final String format = query.substring(index + formatOption.length(), endIndex);
String format = "";
if (index + formatOption.length() < endIndex) {
format = query.substring(index + formatOption.length(), endIndex);
}
return new FormatOptionImpl().setFormat(format);
}
return uriInfo.getFormatOption();