Skip to content
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

Fix ArgumentNullException for: $filter=property in [''] #3122

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

WanjohiSammy
Copy link
Contributor

Issues

This pull request fixes #3092

Description

This PR addresses an issue where the OData URI parser throws an ArgumentNullException when encountering a list with empty string in square brackets.

For example, the following query will throw an ArgumentNullException:

  • /People?$filter=Name in ['']
  • /People?$filter=Name in [ ' ' ]
  • /People?$filter=Name in [ \"\", ' ' ]
  • /People?$filter=Name in [ \"\", '' ]
  • /People?$filter=Name in [\"\"]
  • /People?$filter=Name in [ \"\", \" \" ]
  • /People?$filter=Name in [ \"\" ]
  • /People?$filter=Name in [ '' , ' ' ]
System.InvalidOperationException : An error occurred while processing this request.
---- Microsoft.OData.Client.DataServiceTransportException : System.ArgumentNullException: Value cannot be null or empty. (Parameter 'literalText')
   at Microsoft.OData.ExceptionUtils.CheckArgumentStringNotNullOrEmpty(String value, String parameterName) in C:\Work\odata.net\src\Microsoft.OData.Core\ExceptionUtils.cs:line 101
   .....

Change

This change ensures the square brackets are handle the same way as parentheses when constructing CollectionNode in GetCollectionOperandFromToken method. This method calls the following methods to handle Single and Double quotes:

  • ProcessSingleQuotedStringItem is called to handle single-quoted string items within a collection. This method converts single-quoted strings to double-quoted strings, ensuring compatibility with JSON format. It manages the escaping of single quotes by unescaping double single quotes and escaping double quotes. For example, it converts ''' to "" and 'ghi''' to "ghi'"
  • ProcessDoubleQuotedStringItem is then called to process double-quoted string items within a collection. This method ensures that the string is properly escaped for JSON format, handling the escaping of double quotes and backslashes. For example, it converts "" to "" to avoid passing an empty string to the ConstantNode.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ArgumentNullException for: $filter=property in ['']
1 participant