You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2015/08/10 16:59:00 UTC

olingo-odata4 git commit: [OLINGO-730] UriParser fix

Repository: olingo-odata4
Updated Branches:
  refs/heads/OLINGO-730 [created] 41095dde7


[OLINGO-730] UriParser fix


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

Branch: refs/heads/OLINGO-730
Commit: 41095dde79ed0f8ee08f9e55153b90b62bf3421c
Parents: 6d64cbd
Author: Christian Holzer <c....@sap.com>
Authored: Mon Aug 10 16:58:28 2015 +0200
Committer: Christian Holzer <c....@sap.com>
Committed: Mon Aug 10 16:58:28 2015 +0200

----------------------------------------------------------------------
 .../olingo/server/core/uri/antlr/UriLexer.g4    | 50 ++++++++++----------
 .../core/uri/parser/UriParseTreeVisitor.java    | 14 +++++-
 .../core/uri/antlr/TestFullResourcePath.java    | 46 +++++++++++++++++-
 3 files changed, 82 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/41095dde/lib/server-core/src/main/antlr4/org/apache/olingo/server/core/uri/antlr/UriLexer.g4
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/antlr4/org/apache/olingo/server/core/uri/antlr/UriLexer.g4 b/lib/server-core/src/main/antlr4/org/apache/olingo/server/core/uri/antlr/UriLexer.g4
index f2ec378..ff3db0b 100644
--- a/lib/server-core/src/main/antlr4/org/apache/olingo/server/core/uri/antlr/UriLexer.g4
+++ b/lib/server-core/src/main/antlr4/org/apache/olingo/server/core/uri/antlr/UriLexer.g4
@@ -26,9 +26,9 @@ lexer grammar UriLexer;
 QM              : '?'                 ->        pushMode(MODE_QUERY);               //first query parameter
 AMP             : '&'                 ->        pushMode(MODE_QUERY);               //more query parameters
 STRING          : '\''                -> more,  pushMode(MODE_STRING);              //reads up to next single '
-QUOTATION_MARK  : ('\u0022' | '%22')  -> more,  pushMode(MODE_JSON_STRING);         //reads up to next unescaped "
+QUOTATION_MARK  : '\u0022'            -> more,  pushMode(MODE_JSON_STRING);         //reads up to next unescaped "
 SEARCH_INLINE   : '$search'           ->        pushMode(MODE_SYSTEM_QUERY_SEARCH); //
-FRAGMENT        : '#'                 ->        pushMode(MODE_FRAGMENT); //
+FRAGMENT        : '#'                 ->        pushMode(MODE_FRAGMENT);            //
 
 GEOGRAPHY    : G E O G R A P H Y SQUOTE         -> pushMode(MODE_ODATA_GEO); //TODO make case insensitive
 GEOMETRY     : G E O M E T R Y   SQUOTE         -> pushMode(MODE_ODATA_GEO);
@@ -55,28 +55,28 @@ fragment Y    : 'Y'|'y';
 fragment Z    : 'Z'|'z';
 
 //special chars
-OPEN            : '(' | '%28';
-CLOSE           : ')' | '%29';
-COMMA           : ',' | '%2C';
+OPEN            : '(';
+CLOSE           : ')';
+COMMA           : ',';
 SLASH           : '/';
 POINT           : '.';
 AT              : '@';
 EQ              : '=' ;
 STAR            : '*';
-SEMI            : ';' | '%3b';
+SEMI            : ';';
 COLON           : ':';
 
 EQ_sq           : '='           -> type(EQ);
 AMP_sq          : '&'           -> type(AMP), popMode;
-fragment WS     : ( ' ' | '%09' | '%20' | '%09' );
+fragment WS     : ( ' ' | '\u0009' );
 WSP             : WS+;
 
 //JSON support 
-BEGIN_OBJECT    : WS* ( '{' / '%7B' ) WS*;
-END_OBJECT      : WS* ( '}' / '%7D' ) WS*;
+BEGIN_OBJECT    : WS* '{' WS*;
+END_OBJECT      : WS* '}' WS*;
 
-BEGIN_ARRAY     : WS* ( '[' / '%5B' ) WS*;
-END_ARRAY       : WS* ( ']' / '%5D' ) WS*;
+BEGIN_ARRAY     : WS* '[' WS*;
+END_ARRAY       : WS* ']' WS*;
 
 
 //alpha stuff
@@ -132,7 +132,7 @@ BOOLEAN       :  T R U E |  F A L S E;
 PLUS          : '+';
 
 MINUS         : '-';
-SIGN          : PLUS  | '%2B' | '-';
+SIGN          : PLUS  | '-';
 INT           : SIGN? DIGITS;
 DECIMAL       : INT '.' DIGITS (('e'|'E') SIGN?  DIGITS)?;
 NANINFINITY   : 'NaN' | '-INF' | 'INF';
@@ -334,10 +334,10 @@ AND_sqc             : 'AND'   -> type(AND);
 OR_sqc              : 'OR'    -> type(OR);
 EQ_sqc              : '='     -> type(EQ);
 
-fragment WS_sqc     : ( ' ' | '\u0009' | '%20' | '%09' );
+fragment WS_sqc     : ( ' ' | '\u0009');
 WSP_sqc             : WS_sqc+ -> type(WSP);
 
-QUOTATION_MARK_sqc  : '\u0022' | '%22';
+QUOTATION_MARK_sqc  : '\u0022';
 
 SEARCHWORD          : ('a'..'z'|'A'..'Z')+;
 SEARCHPHRASE        : QUOTATION_MARK_sqc ~["]* QUOTATION_MARK_sqc -> popMode;
@@ -356,7 +356,7 @@ mode MODE_JSON_STRING;
 // Any """ characters inside a string are escaped with "\".
 //;==============================================================================
 
-STRING_IN_JSON      : ('\\"' | ~[\u0022] )* ('"' | '%22') -> popMode;
+STRING_IN_JSON      : ('\\"' | ~[\u0022] )* '"' -> popMode;
 
 //;==============================================================================
 mode MODE_ODATA_GEO;
@@ -379,21 +379,21 @@ fragment T_  : 't'|'T';
 fragment U_  : 'u'|'U';
 fragment Y_  : 'y'|'Y';
 
-fragment SP_g   : ' ';//'\u0020'; // a simple space
-fragment WS_g   : ( ' ' | '%20' | '%09' );
+fragment SP_g   : ' ';                  //'\u0020'; // a simple space
+fragment WS_g   : ( ' ' | '\u0009' );
 
-OPEN_g          : ('(' | '%28') -> type(OPEN);
-CLOSE_g         : (')' | '%29') -> type(CLOSE);
-COMMA_g         : (',' | '%2C') -> type(COMMA);
+OPEN_g          : '('   -> type(OPEN);
+CLOSE_g         : ')'   -> type(CLOSE);
+COMMA_g         : ','   -> type(COMMA);
 WSP_g           : WS_g+ -> type(WSP);
-POINT_g         : '.' -> type(POINT);
-AT_g            : '@' -> type(AT);
-SEMI_g            : (';' | '%3B') -> type(SEMI);
-EQ_g            : '=' -> type(EQ);
+POINT_g         : '.'   -> type(POINT);
+AT_g            : '@'   -> type(AT);
+SEMI_g          : ';'   -> type(SEMI);
+EQ_g            : '='   -> type(EQ);
 
 fragment DIGIT_g    : '0'..'9';
 fragment DIGITS_g   : DIGIT_g+;
-SIGN_g              : ('+' | '%2B' |'-') -> type(SIGN);
+SIGN_g              : ('+' | '-') -> type(SIGN);
 INT_g               : SIGN_g? DIGITS_g -> type(INT);
 DECIMAL_g           : 'SS' INT_g '.' DIGITS_g (('e'|'E') SIGN_g?  DIGITS_g)? -> type(DECIMAL);
 COLLECTION_g        : C_ O_ L_ L_ E_ C_ T_ I_ O_ N_ -> type(COLLECTION);

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/41095dde/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
index 2ed6d19..9a5bd6f 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
@@ -455,6 +455,11 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
         }
       } else if (property instanceof EdmNavigationProperty) {
         // create navigation property
+        if(ctx.getParent() instanceof ExpandPathContext && ctx.vlNVO.size() > 0) {
+          throw wrap(new UriParserSemanticException("Navigation properties in expand system query options must not" 
+                + " be followed a an key", UriParserSemanticException.MessageKeys.KEY_NOT_ALLOWED));
+        }
+        
         UriResourceNavigationPropertyImpl navigationResource = new UriResourceNavigationPropertyImpl()
             .setNavigationProperty((EdmNavigationProperty) property);
         context.contextUriInfo.addResourcePart(navigationResource);
@@ -1213,7 +1218,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
     // set tmp context
     context.contextExpandItemPath = expandItem;
     context.contextUriInfo = new UriInfoImpl().setKind(UriInfoKind.resource);
-
+    
     super.visitExpandPath(ctx);
 
     EdmType startType = removeUriResourceStartingTypeFilterImpl(context.contextUriInfo);
@@ -1228,7 +1233,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
 
     return expandItem;
   }
-
+  
   @Override
   public Object visitExpandPathExtension(final ExpandPathExtensionContext ctx) {
     List<SystemQueryOptionImpl> list = new ArrayList<SystemQueryOptionImpl>();
@@ -1733,6 +1738,11 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
     if (ctx.vlNVO.size() > 0) {
       // check for keyPredicates
       if (pathInfoSegment instanceof UriResourceWithKeysImpl) {
+        if(ctx.vlNVO.size() > 1) {
+          throw wrap(new UriParserSemanticException("More than one key predicates found", 
+              UriParserSemanticException.MessageKeys.WRONG_NUMBER_OF_KEY_PROPERTIES));
+        }
+        
         @SuppressWarnings("unchecked")
         List<UriParameterImpl> list = (List<UriParameterImpl>) ctx.vlNVO.get(0).accept(this);
         ((UriResourceWithKeysImpl) pathInfoSegment)

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/41095dde/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
index 10240ab..e3f4b9b 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
@@ -5274,7 +5274,51 @@ public class TestFullResourcePath {
     .goUpUriValidator()
     .isCustomParameter(0, "@A", "'2'");
   }
-
+  
+  @Test(expected=UriParserException.class)
+  public void testDoublePercentDecoding() throws Exception {
+    testUri.run("ESAllPrim%252832767%29");
+  }
+  
+  @Test(expected=UriParserException.class)
+  public void testMultipleKeysInResourcePath() throws Exception {
+    // See OLINGO-730
+    testUri.run("ESAllPrim(32767)(1)(2)");
+  }
+  
+  @Test(expected=UriParserException.class)
+  public void testSimpleKeyInExpandSystemQueryOption() throws Exception {
+    testUri.run("ESAllPrim(0)", "$expand=NavPropertyETTwoPrimMany(-365)($filter=PropertyString eq 'Test String1')");
+  }
+  
+  @Test(expected=UriParserException.class)
+  public void testCompountKeyInExpandSystemQueryOption() throws Exception {
+    testUri.run("ESAllPrim(0)", "$expand=NavPropertyETTwoPrimMany(PropertyInt16=1,PropertyString=2)" 
+             + "($filter=PropertyString eq 'Test String1')");
+  }
+  
+  @Test(expected=UriParserException.class)
+  public void testFilterSystemQueryOptionAnyWithKeyAny() throws Exception {
+    testUri.run("ESAllPrim", "$filter=NavPropertyETTwoPrimMany(1)" 
+              + "/any(d:d/PropertyInt16 eq 0)");
+  }
+  
+  @Test(expected=UriParserException.class)
+  public void testFilterSystemQueryOptionAnyWithKeyAll() throws Exception {
+    testUri.run("ESAllPrim", "$filter=NavPropertyETTwoPrimMany(1)" 
+              + "/all(d:d/PropertyInt16 eq 0)");
+  }
+  
+  @Test
+  public void testNavigationPropertyWithCount() throws Exception {
+    testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany/$count")
+           .goPath().at(0).isEntitySet("ESKeyNav").isKeyPredicate(0, "PropertyInt16", "1")
+           .at(1).isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, true)
+           .at(2).isCount();
+  }
+  
+  // ESKeyNav(1)/NavPropertyETTwoKeyNavMany/$count
+  
   public static String encode(final String decoded) throws UnsupportedEncodingException {
     return Encoder.encode(decoded);
   }