@@ -13,6 +13,7 @@ namespace Microsoft.OData.UriParser
13
13
using System . Text ;
14
14
using Microsoft . OData . Edm ;
15
15
using Microsoft . OData . Core ;
16
+ using System . Collections . Generic ;
16
17
17
18
/// <summary>
18
19
/// Class that knows how to bind the In operator.
@@ -129,7 +130,7 @@ private CollectionNode GetCollectionOperandFromToken(QueryToken queryToken, IEdm
129
130
Debug . Assert ( expectedType . IsCollection ( ) ) ;
130
131
string expectedTypeFullName = expectedType . Definition . AsElementType ( ) . FullTypeName ( ) ;
131
132
132
- if ( expectedTypeFullName . Equals ( "Edm.String" , StringComparison . Ordinal ) || expectedTypeFullName . Equals ( "Edm.Untyped" , StringComparison . Ordinal ) )
133
+ if ( expectedTypeFullName . Equals ( "Edm.String" , StringComparison . Ordinal ) || ( expectedTypeFullName . Equals ( "Edm.Untyped" , StringComparison . Ordinal ) && IsCollectionContentEmptyOrSpaces ( bracketLiteralText ) ) )
133
134
{
134
135
// For collection of strings, need to convert single-quoted string to double-quoted string,
135
136
// and also, per ABNF, a single quote within a string literal is "encoded" as two consecutive single quotes in either
@@ -423,5 +424,76 @@ private static string NormalizeDateTimeCollectionItems(string bracketLiteralText
423
424
424
425
return "[" + String . Join ( "," , items ) + "]" ;
425
426
}
427
+
428
+ private static bool IsCollectionContentEmptyOrSpaces ( string bracketLiteralText )
429
+ {
430
+ if ( string . IsNullOrWhiteSpace ( bracketLiteralText ) || bracketLiteralText . Length < 2 )
431
+ {
432
+ return true ;
433
+ }
434
+
435
+ string content = bracketLiteralText [ 1 ..^ 1 ] . Trim ( ) ;
436
+
437
+ if ( string . IsNullOrWhiteSpace ( content ) )
438
+ {
439
+ return true ;
440
+ }
441
+
442
+ bool isEmptyOrHasOnlySpaces = true ;
443
+ bool isCharinsideQuotes = false ;
444
+ char quoteChar = '\0 ' ;
445
+ Span < char > buffer = stackalloc char [ content . Length ] ;
446
+ int bufferIndex = 0 ;
447
+
448
+ for ( int i = 0 ; i < content . Length ; i ++ )
449
+ {
450
+ char c = content [ i ] ;
451
+
452
+ if ( isCharinsideQuotes )
453
+ {
454
+ if ( c == quoteChar )
455
+ {
456
+ isCharinsideQuotes = false ;
457
+ }
458
+ buffer [ bufferIndex ++ ] = c ;
459
+ }
460
+ else
461
+ {
462
+ if ( c == '"' || c == '\' ' )
463
+ {
464
+ isCharinsideQuotes = true ;
465
+ quoteChar = c ;
466
+ buffer [ bufferIndex ++ ] = c ;
467
+ }
468
+ else if ( c == ',' )
469
+ {
470
+ string item = new string ( buffer [ ..bufferIndex ] ) . Trim ( ) . Trim ( '\' ' , '"' ) ;
471
+
472
+ if ( ! string . IsNullOrWhiteSpace ( item ) )
473
+ {
474
+ isEmptyOrHasOnlySpaces = false ;
475
+ break ;
476
+ }
477
+ bufferIndex = 0 ;
478
+ }
479
+ else
480
+ {
481
+ buffer [ bufferIndex ++ ] = c ;
482
+ }
483
+ }
484
+ }
485
+
486
+ if ( bufferIndex > 0 )
487
+ {
488
+ string lastItem = new string ( buffer [ ..bufferIndex ] ) . Trim ( ) . Trim ( '\' ' , '"' ) ;
489
+
490
+ if ( ! string . IsNullOrWhiteSpace ( lastItem ) )
491
+ {
492
+ isEmptyOrHasOnlySpaces = false ;
493
+ }
494
+ }
495
+
496
+ return isEmptyOrHasOnlySpaces ;
497
+ }
426
498
}
427
499
}
0 commit comments