Repository: olingo-odata4
Updated Branches:
  refs/heads/master 8f1a079fa -> 891421d7f


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


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/891421d7
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/891421d7
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/891421d7

Branch: refs/heads/master
Commit: 891421d7fccf79786de97e98b140a65818d854b9
Parents: 8f1a079
Author: ramya vasanth <[email protected]>
Authored: Wed Jun 21 14:01:05 2017 +0530
Committer: ramya vasanth <[email protected]>
Committed: Wed Jun 21 14:01:05 2017 +0530

----------------------------------------------------------------------
 .../olingo/fit/tecsvc/http/BasicHttpITCase.java | 24 ++++++++++++++++++++
 .../olingo/server/core/ODataHandlerImpl.java    |  5 +++-
 2 files changed, 28 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/891421d7/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicHttpITCase.java
----------------------------------------------------------------------
diff --git 
a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicHttpITCase.java 
b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicHttpITCase.java
index 55a04f5..775fd30 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicHttpITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicHttpITCase.java
@@ -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 
''."));
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/891421d7/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandlerImpl.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandlerImpl.java
 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandlerImpl.java
index d1a9cf2..0bc59be 100644
--- 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandlerImpl.java
+++ 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandlerImpl.java
@@ -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();

Reply via email to