-
Notifications
You must be signed in to change notification settings - Fork 182
Open
Labels
bugSomething isn't workingSomething isn't working
Description
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
- Create an OData controller with the following action method:
[Route("odata/test")]
public IActionResult Get(ODataQueryOptions<TEntity> options)
{
//...
}- 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()
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working