Skip to content

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

Merged
merged 6 commits into from
Mar 11, 2025

Conversation

ElizabethOkerio
Copy link
Contributor

@ElizabethOkerio ElizabethOkerio commented Feb 28, 2025

Issues

*This pull request fixes #3098, fixes #2875 *

Description

This PR (#2711) introduced a fix to support $filter=dynamicProperty in (''). However, the changes in this PR inadvertently broke the handling of $filter=dynamicProperty in (primitive collections), such as $filter=dynamicProperty in (1,2,3).

To address this, I've added a private method, IsCollectionContentEmptyOrSpaces, which checks whether a collection of Edm.Untyped is either empty or contains only spaces before further processing. If the collection meets this condition, the logic for ensuring a string collection gets properly formatted gets called.

Previously, this string formatting logic was executed without verifying whether the Edm.Untyped collection contained empty spaces or not. As a result, it was being applied even when the collection contained primitive types (e.g., numbers) that do not require string formatting, leading to exceptions being thrown.

Checklist (Uncheck if it is not completed)

  • Test cases added
  • Build and test with one-click build and test script passed

Additional work necessary

If documentation update is needed, please add "Docs Needed" label to the issue and provide details about the required document change in the issue.

@ElizabethOkerio ElizabethOkerio changed the title Fix filter in a collection of primitive values. Fix filter in a collection of dynamic primitive values. Feb 28, 2025
@ElizabethOkerio
Copy link
Contributor Author

Run pipeline

@ElizabethOkerio ElizabethOkerio changed the title Fix filter in a collection of dynamic primitive values. Fix filter in a collection of dynamic primitive values exa ?$filter in (1,2,3) Mar 3, 2025
@ElizabethOkerio ElizabethOkerio changed the title Fix filter in a collection of dynamic primitive values exa ?$filter in (1,2,3) Fix $filter in (collectionofdynamicprimitivevalues) Mar 3, 2025
@ElizabethOkerio ElizabethOkerio changed the title Fix $filter in (collectionofdynamicprimitivevalues) Fix $filter in (collectionofdynamicprimitivevalues) Mar 3, 2025
@ElizabethOkerio ElizabethOkerio changed the title Fix $filter in (collectionofdynamicprimitivevalues) Fix $filter in (collectionofdynamicprimitivevalues) Mar 3, 2025

string content = bracketLiteralText[1..^1].Trim();

if (string.IsNullOrWhiteSpace(content))
Copy link
Contributor

Choose a reason for hiding this comment

The 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 string.IsNullOrWhiteSpace at the beginning of this method

Copy link
Contributor Author

@ElizabethOkerio ElizabethOkerio Mar 4, 2025

Choose a reason for hiding this comment

The 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 null or empty whitespaces without the brackets. So the check for isNullOrWhiteSpace will always return false.

@habbes
Copy link
Contributor

habbes commented Mar 4, 2025

I'm not opposed to this PR, but the way handle collection literals seems like a hack and all these PRs we make to patch edge cases are band-aids that are not sustainable in the long term. We should not be hacking the collection string to massage it into a JSON array so that we can parse it and then do special checks for edge cases. I believe the ideal, sustainable solution would be to handle the collection property from the lexer stage. By the time we get to the parser, we have an array start token, and array end token, and we know all the elements in between, the elements would have been properly tokenized based on the tokenizer rules for these literals.

@ElizabethOkerio ElizabethOkerio merged commit ef70951 into OData:main Mar 11, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants