|
7 | 7 | namespace Microsoft.OData.UriParser
|
8 | 8 | {
|
9 | 9 | using System;
|
| 10 | + using System.Buffers; |
10 | 11 | using System.Diagnostics;
|
11 | 12 | using System.Globalization;
|
12 | 13 | using System.Linq;
|
13 | 14 | using System.Text;
|
14 |
| - using Microsoft.OData.Edm; |
15 | 15 | using Microsoft.OData.Core;
|
| 16 | + using Microsoft.OData.Edm; |
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) && IsCollectionEmptyOrWhiteSpace(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,78 @@ private static string NormalizeDateTimeCollectionItems(string bracketLiteralText
|
423 | 424 |
|
424 | 425 | return "[" + String.Join(",", items) + "]";
|
425 | 426 | }
|
| 427 | + |
| 428 | + private static bool IsCollectionEmptyOrWhiteSpace(string bracketLiteralText) |
| 429 | + { |
| 430 | + string content = bracketLiteralText[1..^1].Trim(); |
| 431 | + |
| 432 | + if (string.IsNullOrWhiteSpace(content)) |
| 433 | + { |
| 434 | + return true; |
| 435 | + } |
| 436 | + |
| 437 | + bool isEmptyOrWhiteSpace = true; |
| 438 | + bool isCharInsideQuotes = false; |
| 439 | + char quoteChar = '\0'; |
| 440 | + char[] buffer = ArrayPool<char>.Shared.Rent(content.Length); |
| 441 | + int bufferIndex = 0; |
| 442 | + |
| 443 | + try |
| 444 | + { |
| 445 | + for (int i = 0; i < content.Length; i++) |
| 446 | + { |
| 447 | + char c = content[i]; |
| 448 | + |
| 449 | + if (isCharInsideQuotes) |
| 450 | + { |
| 451 | + if (c == quoteChar) |
| 452 | + { |
| 453 | + isCharInsideQuotes = false; |
| 454 | + } |
| 455 | + buffer[bufferIndex++] = c; |
| 456 | + } |
| 457 | + else |
| 458 | + { |
| 459 | + if (c == '"' || c == '\'') |
| 460 | + { |
| 461 | + isCharInsideQuotes = true; |
| 462 | + quoteChar = c; |
| 463 | + buffer[bufferIndex++] = c; |
| 464 | + } |
| 465 | + else if (c == ',') |
| 466 | + { |
| 467 | + string item = new string(buffer, 0, bufferIndex).Trim().Trim('\'', '"'); |
| 468 | + |
| 469 | + if (!string.IsNullOrWhiteSpace(item)) |
| 470 | + { |
| 471 | + isEmptyOrWhiteSpace = false; |
| 472 | + break; |
| 473 | + } |
| 474 | + bufferIndex = 0; |
| 475 | + } |
| 476 | + else |
| 477 | + { |
| 478 | + buffer[bufferIndex++] = c; |
| 479 | + } |
| 480 | + } |
| 481 | + } |
| 482 | + |
| 483 | + if (bufferIndex > 0) |
| 484 | + { |
| 485 | + string lastItem = new string(buffer, 0, bufferIndex).Trim().Trim('\'', '"'); |
| 486 | + |
| 487 | + if (!string.IsNullOrWhiteSpace(lastItem)) |
| 488 | + { |
| 489 | + isEmptyOrWhiteSpace = false; |
| 490 | + } |
| 491 | + } |
| 492 | + } |
| 493 | + finally |
| 494 | + { |
| 495 | + ArrayPool<char>.Shared.Return(buffer); |
| 496 | + } |
| 497 | + |
| 498 | + return isEmptyOrWhiteSpace; |
| 499 | + } |
426 | 500 | }
|
427 | 501 | }
|
0 commit comments