@@ -461,9 +461,13 @@ private void CreateCosmosQuery(CosmosDBQuery query,ServiceCursorDef cursorDef, I
461461 IEnumerable < string > projection = query . Projection ;
462462 string element ;
463463 string projectionList = string . Empty ;
464+ string regexSpecialChars = "[^A-Za-z0-9]" ;
464465 foreach ( string key in projection )
465466 {
466- element = $ "{ TABLE_ALIAS } .{ key } ";
467+ if ( Regex . IsMatch ( key , regexSpecialChars ) )
468+ element = $ "{ TABLE_ALIAS } [\" { key } \" ]";
469+ else
470+ element = $ "{ TABLE_ALIAS } .{ key } ";
467471 if ( ! string . IsNullOrEmpty ( projectionList ) )
468472 projectionList = $ "{ element } ,{ projectionList } ";
469473 else
@@ -550,7 +554,10 @@ private void CreateCosmosQuery(CosmosDBQuery query,ServiceCursorDef cursorDef, I
550554 foreach ( string d in projection )
551555 {
552556 string wholeWordPattern = String . Format ( @"\b{0}\b" , d ) ;
553- filterProcess = Regex . Replace ( filterProcess , wholeWordPattern , $ "{ TABLE_ALIAS } .{ d } ") ;
557+ if ( Regex . IsMatch ( wholeWordPattern , regexSpecialChars ) )
558+ filterProcess = Regex . Replace ( filterProcess , wholeWordPattern , $ "{ TABLE_ALIAS } [\" { d } \" ]") ;
559+ else
560+ filterProcess = Regex . Replace ( filterProcess , wholeWordPattern , $ "{ TABLE_ALIAS } .{ d } ") ;
554561 }
555562 keyFilterQ = new string [ ] { filterProcess } ;
556563 allFiltersQuery = allFiltersQuery . Concat ( keyFilterQ ) ;
@@ -563,7 +570,10 @@ private void CreateCosmosQuery(CosmosDBQuery query,ServiceCursorDef cursorDef, I
563570
564571 foreach ( string orderAtt in query . OrderBys )
565572 {
566- expression = orderAtt . StartsWith ( "(" ) ? $ "{ TABLE_ALIAS } .{ orderAtt . Remove ( orderAtt . Length - 1 , 1 ) . Remove ( 0 , 1 ) } DESC" : $ "{ TABLE_ALIAS } .{ orderAtt } ASC";
573+ if ( ! Regex . IsMatch ( orderAtt , regexSpecialChars ) )
574+ expression = orderAtt . StartsWith ( "(" ) ? $ "{ TABLE_ALIAS } .{ orderAtt . Remove ( orderAtt . Length - 1 , 1 ) . Remove ( 0 , 1 ) } DESC" : $ "{ TABLE_ALIAS } .{ orderAtt } ASC";
575+ else
576+ expression = orderAtt . StartsWith ( "(" ) ? $ "{ TABLE_ALIAS } [\" { orderAtt . Remove ( orderAtt . Length - 1 , 1 ) . Remove ( 0 , 1 ) } \" ] DESC" : $ "{ TABLE_ALIAS } [\" { orderAtt } \" ] ASC";
567577 orderExpressionList = orderExpressionList . Concat ( new string [ ] { expression } ) ;
568578 }
569579
0 commit comments