Skip to content

Filter operator "IN" fails to handle empty strings. #3363

@EvanSchallerer

Description

@EvanSchallerer

Describe the bug

Providing an empty string value ('') to the IN filter operator throws an ArgumentNullException.
Example OData query: /mytable?$filter=Name in ('value1', '')

Assemblies affected

Microsoft.OData.Core 8.4.0
Note: Microsoft.OData.Core 7.21.4 did not throw an exception in this case, but instead incorrectly parsed the '' value as \"\" which also seems like a bug.

Steps to Reproduce

This short gist reproduces the issue: https://gist.github.com/EvanSchallerer/8dc8d14c53c310e4a87ae54d20573b29

Expected behaviour

Empty string values ('') should parse as the empty string and not throw an exception. They should also not parse as a quoted empty string (\"\") as they did in 7.x.x.

Actual behaviour

ODataQueryOptionParser.ParseFilter() throws an ArgumentNullException when provided with an empty string value for an IN filter.

Additional details

The CollectionConstantNode constructor validates that the literalText parameter is not null or empty which throws the offending ArgumentNullException.

ExceptionUtils.CheckArgumentStringNotNullOrEmpty(literalText, "literalText");

Stack trace:

   at Microsoft.OData.ExceptionUtils.CheckArgumentStringNotNullOrEmpty(String value, String parameterName)
   at Microsoft.OData.UriParser.ConstantNode..ctor(Object constantValue, String literalText, IEdmTypeReference typeReference)
   at Microsoft.OData.UriParser.CollectionConstantNode..ctor(IEnumerable`1 objectCollection, String literalText, IEdmCollectionTypeReference collectionType)
   at Microsoft.OData.UriParser.LiteralBinder.BindInLiteral(LiteralToken literalToken)
   at Microsoft.OData.UriParser.MetadataBinder.<BindIn>b__22_0(QueryToken queryToken)
   at Microsoft.OData.UriParser.InBinder.GetCollectionOperandFromToken(QueryToken queryToken, IEdmTypeReference expectedType, IEdmModel model)
   at Microsoft.OData.UriParser.InBinder.BindInOperator(InToken inToken, BindingState state)
   at Microsoft.OData.UriParser.MetadataBinder.BindIn(InToken inToken)
   at Microsoft.OData.UriParser.MetadataBinder.Bind(QueryToken token)
   at Microsoft.OData.UriParser.FilterBinder.BindFilter(QueryToken filter)
   at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseFilterImplementation(String filter, ODataUriParserConfiguration configuration, ODataPathInfo odataPathInfo)
   at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseFilter()

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions