Skip to content

ODataQueryOptions binding throws an ArgumentException with a whitespace query param #1055

@axnetg

Description

@axnetg

Assemblies affected
ASP.NET Core OData 8.x

Describe the bug
Sending a request with a query param where the key is whitespace throws an ArgumentException when trying to bind the ODataQueryOptions model in a controller.

Reproduce steps

  1. Create an OData controller with the following action method:
[Route("odata/test")]
public IActionResult Get(ODataQueryOptions<TEntity> options)
{
    //...
}
  1. Send a request to the following endpoint (note the trailing &%20):
/odata/test?$top=10&$skip=0&%20

Expected behavior
The ODataQueryOptions object should be bound successfully ignoring the empty query param.

Additional context
The issue is reproducible using .NET 6.
The empty query param doesn't need to be placed at the end.
When ODataOptions.EnableNoDollarQueryOptions is false the exception is NOT thrown and binding behaves as expected.

System.ArgumentException: The argument 'queryOptionName' is null or empty. (Parameter 'queryOptionName')
   at Microsoft.AspNetCore.OData.Query.ODataQueryOptions.IsSupportedQueryOption(String queryOptionName)
   at Microsoft.AspNetCore.OData.Query.ODataQueryOptions.GetODataQueryParameters()
   at Microsoft.AspNetCore.OData.Query.ODataQueryOptions.Initialize(ODataQueryContext context)
   at Microsoft.AspNetCore.OData.Query.ODataQueryOptions`1..ctor(ODataQueryContext context, HttpRequest request)
   at Microsoft.AspNetCore.OData.Query.ODataQueryParameterBindingAttribute.ODataQueryParameterBinding.CreateODataQueryOptions[T](ODataQueryContext context, HttpRequest request)
   at Microsoft.AspNetCore.OData.Query.ODataQueryParameterBindingAttribute.ODataQueryParameterBinding.BindModelAsync(ModelBindingContext bindingContext)
   at Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BinderTypeModelBinder.BindModelAsync(ModelBindingContext bindingContext)
   at Microsoft.AspNetCore.Mvc.ModelBinding.ParameterBinder.BindModelAsync(ActionContext actionContext, IModelBinder modelBinder, IValueProvider valueProvider, ParameterDescriptor parameter, ModelMetadata metadata, Object value, Object container)
   at Microsoft.AspNetCore.Mvc.Controllers.ControllerBinderDelegateProvider.<>c__DisplayClass0_0.<<CreateBinderDelegate>g__Bind|0>d.MoveNext()

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions