[OLINGO-846] Trim query option values

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

Branch: refs/heads/master
Commit: 570f4317ce857b55c3f336eae32858c88acfaf8e
Parents: e5d1e82
Author: Christian Amend <[email protected]>
Authored: Fri Mar 18 14:59:00 2016 +0100
Committer: Christian Amend <[email protected]>
Committed: Mon Mar 21 10:09:20 2016 +0100

----------------------------------------------------------------------
 .../olingo/server/core/uri/parser/UriDecoder.java    |  3 ++-
 .../server/core/uri/parser/TestFullResourcePath.java | 15 +++++++++++++--
 2 files changed, 15 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/570f4317/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriDecoder.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriDecoder.java
 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriDecoder.java
index 1cc5ec5..4a94e85 100644
--- 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriDecoder.java
+++ 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriDecoder.java
@@ -48,7 +48,8 @@ public class UriDecoder {
     for (final String option : split(queryOptionString, '&')) {
       final int pos = option.indexOf('=');
       final String name = pos >= 0 ? option.substring(0, pos)  : option;
-      final String text = pos >= 0 ? option.substring(pos + 1) : "";
+      //OLINGO-846 We trim the query option text to be more lenient to wrong 
uri constructors
+      final String text = pos >= 0 ? option.substring(pos + 1).trim() : "";
       queryOptions.add(new CustomQueryOptionImpl()
           .setName(decode(name))
           .setText(decode(text)));

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/570f4317/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/TestFullResourcePath.java
----------------------------------------------------------------------
diff --git 
a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/TestFullResourcePath.java
 
b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/TestFullResourcePath.java
index 64cf757..e3c798d 100644
--- 
a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/TestFullResourcePath.java
+++ 
b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/TestFullResourcePath.java
@@ -58,6 +58,17 @@ public class TestFullResourcePath {
   private final FilterValidator testFilter = new FilterValidator().setEdm(edm);
 
   @Test
+  public void trimQueryOptionsValue() throws Exception {
+    // OLINGO-846 trim query option value
+    testUri.run("ESAllPrim", "$filter= PropertyInt16 eq 12 ")
+        .isKind(UriInfoKind.resource).goPath()
+        .first().isEntitySet("ESAllPrim");
+    // OLINGO-846 trim query option value
+    testUri.run("ESAllPrim", "$filter= PropertyInt16 eq 12 ")
+        
.isKind(UriInfoKind.resource).goFilter().isBinary(BinaryOperatorKind.EQ).is("<<PropertyInt16>
 eq <12>>");
+  }
+
+  @Test
   public void valueOnNonMediaEntity() throws Exception {
     
testUri.runEx("ESAllPrim/$value").isExSemantic(UriParserSemanticException.MessageKeys.ONLY_FOR_TYPED_PARTS);
     testUri.runEx("ESAllPrim(1)/NavPropertyETTwoPrimMany/$value").isExSemantic(
@@ -952,14 +963,14 @@ public class TestFullResourcePath {
         "$expand=ESTwoPrim")
         .goExpand()
         .first().goPath().first().isEntitySet("ESTwoPrim");
-    
+
     testUri.run("$crossjoin(ESTwoPrim,ESAllPrim)",
         "$expand=ESTwoPrim,ESAllPrim")
         .goExpand()
         .first().goPath().first().isEntitySet("ESTwoPrim")
         
.goUpExpandValidator().next().goPath().first().isEntitySet("ESAllPrim");
 
-    //TODO: Once crossjoin is implemented these tests should no longer result 
in errors
+    // TODO: Once crossjoin is implemented these tests should no longer result 
in errors
 //    testUri.run("$crossjoin(ESTwoPrim,ESAllPrim)",
 //        "$expand=ESAllPrim/NavPropertyETTwoPrimOne")
 //        .goExpand()

Reply via email to