-
Notifications
You must be signed in to change notification settings - Fork 359
Fix $filter in (collectionofdynamicprimitivevalues) #3190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
cdefde9
a425842
5f9e72a
275dec3
e409415
aa257ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,7 +129,7 @@ private CollectionNode GetCollectionOperandFromToken(QueryToken queryToken, IEdm | |
Debug.Assert(expectedType.IsCollection()); | ||
string expectedTypeFullName = expectedType.Definition.AsElementType().FullTypeName(); | ||
|
||
if (expectedTypeFullName.Equals("Edm.String", StringComparison.Ordinal) || expectedTypeFullName.Equals("Edm.Untyped", StringComparison.Ordinal)) | ||
if (expectedTypeFullName.Equals("Edm.String", StringComparison.Ordinal) || (expectedTypeFullName.Equals("Edm.Untyped", StringComparison.Ordinal) && IsCollectionContentEmptyOrSpaces(bracketLiteralText))) | ||
{ | ||
// For collection of strings, need to convert single-quoted string to double-quoted string, | ||
// and also, per ABNF, a single quote within a string literal is "encoded" as two consecutive single quotes in either | ||
|
@@ -423,5 +423,76 @@ private static string NormalizeDateTimeCollectionItems(string bracketLiteralText | |
|
||
return "[" + String.Join(",", items) + "]"; | ||
} | ||
|
||
private static bool IsCollectionContentEmptyOrSpaces(string bracketLiteralText) | ||
ElizabethOkerio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
if (string.IsNullOrWhiteSpace(bracketLiteralText) || bracketLiteralText.Length < 2) | ||
ElizabethOkerio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
return true; | ||
} | ||
|
||
string content = bracketLiteralText[1..^1].Trim(); | ||
|
||
if (string.IsNullOrWhiteSpace(content)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Depending on the answer to this https://github.com/OData/odata.net/pull/3190/files#r1978721142, is this scenario possible? I think that the first thing we should check is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is after removing the first and last brackets and trimming the spaces before and after content. I also don't think at this point we can have |
||
{ | ||
return true; | ||
} | ||
|
||
bool isEmptyOrHasOnlySpaces = true; | ||
ElizabethOkerio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
bool isCharinsideQuotes = false; | ||
char quoteChar = '\0'; | ||
Span<char> buffer = stackalloc char[content.Length]; | ||
ElizabethOkerio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
int bufferIndex = 0; | ||
|
||
for (int i = 0; i < content.Length; i++) | ||
{ | ||
char c = content[i]; | ||
|
||
if (isCharinsideQuotes) | ||
{ | ||
if (c == quoteChar) | ||
{ | ||
isCharinsideQuotes = false; | ||
} | ||
buffer[bufferIndex++] = c; | ||
} | ||
else | ||
{ | ||
if (c == '"' || c == '\'') | ||
{ | ||
isCharinsideQuotes = true; | ||
quoteChar = c; | ||
buffer[bufferIndex++] = c; | ||
} | ||
else if (c == ',') | ||
{ | ||
string item = new string(buffer[..bufferIndex]).Trim().Trim('\'', '"'); | ||
|
||
if (!string.IsNullOrWhiteSpace(item)) | ||
{ | ||
isEmptyOrHasOnlySpaces = false; | ||
break; | ||
} | ||
bufferIndex = 0; | ||
} | ||
else | ||
{ | ||
buffer[bufferIndex++] = c; | ||
} | ||
} | ||
} | ||
|
||
if (bufferIndex > 0) | ||
{ | ||
string lastItem = new string(buffer[..bufferIndex]).Trim().Trim('\'', '"'); | ||
|
||
if (!string.IsNullOrWhiteSpace(lastItem)) | ||
{ | ||
isEmptyOrHasOnlySpaces = false; | ||
} | ||
} | ||
|
||
return isEmptyOrHasOnlySpaces; | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.