OData / odata.net

ODataLib: Open Data Protocol - .NET Libraries and Frameworks
https://docs.microsoft.com/odata
Other
687 stars 349 forks source link

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

Open WanjohiSammy opened 4 days ago

WanjohiSammy commented 4 days ago

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:

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 Empty String in 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:

Checklist (Uncheck if it is not completed)

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.

gathogojr commented 22 hours ago

@WanjohiSammy This change ensures the square brackets are handle the same way as parentheses when constructing CollectionNode in GetCollectionOperandFromToken method:

WanjohiSammy commented 20 hours ago

@gathogojr

  • Is use of square brackets in the same manner as parentheses supported by the OData standard?
  • Can you confirm that we support non-empty square brackets? For example, $filter=Name in ['Sue','Joe']. Maybe even add a test

I have updated the PR description to reflect correctly that this was failing because the empty string in square brackets was not handle the same as empty string in parenthesis

gathogojr commented 6 hours ago

@WanjohiSammy Can you confirm what I asked here https://github.com/OData/odata.net/pull/3122#issuecomment-2485561072

gathogojr commented 5 hours ago

@WanjohiSammy I have confirmed that we support brackets, i.e., Books?$filter=Title in ('Harry Porter') and Books?$filter=Title in ['Harry Porter'] are both handled fine by the library

WanjohiSammy commented 4 hours ago

@gathogojr

Can you confirm what I asked here #3122 (comment)

I thought I confirmed here https://github.com/OData/odata.net/pull/3122#issuecomment-2485847253 The issue solved by this PR is when there is an empty string in square brackets.

-We do support square brackets but in case of empty string in these brackets an exception is thrown. -Since there is no exception with Empty string in parenthesis, this change ensures empty string in square brackets are treated the same as empty string in parenthesis.