[OLINGO-1322]ODATA V2.0: An empty string validation in UriParser
authorArchana Rai <archana.rai@sap.com>
Thu, 13 Dec 2018 08:38:06 +0000 (14:08 +0530)
committerArchana Rai <archana.rai@sap.com>
Thu, 13 Dec 2018 08:38:06 +0000 (14:08 +0530)
odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriParserImpl.java
odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/uri/UriParserTest.java

index 8373df7..3a31ad7 100644 (file)
@@ -468,6 +468,10 @@ public class UriParserImpl extends UriParser {
           throw new UriSyntaxException(UriSyntaxException.MISSINGKEYPREDICATENAME.addContent(key));
         }
       }
+      
+      if("''".equals(value) || value==null){
+        throw new UriSyntaxException(UriSyntaxException.INVALIDVALUE.addContent(value));
+      }
 
       EdmProperty keyProperty = null;
       for (final EdmProperty testKeyProperty : keyProperties) {
index f08012a..51a2669 100644 (file)
@@ -254,6 +254,17 @@ public class UriParserTest extends BaseTest {
     assertEquals("1", result.getKeyPredicates().get(0).getLiteral());
     assertEquals("EmployeeId", result.getKeyPredicates().get(0).getProperty().getName());
   }
+  
+  @Test
+  public void parseEmployeesEntityWithEmptyKey() throws Exception {
+    parseWrongUri("/Employees('')", UriSyntaxException.INVALIDVALUE.addContent("''"));
+  }
+  
+  @Test
+  public void parseEmployeesEntityWithNullKey() throws Exception {
+    parseWrongUri("/Employees(null)", UriSyntaxException.INCOMPATIBLELITERAL);
+  }
+
 
   @Test
   public void parseEmployeesEntityWithKeyWithComma() throws Exception {