Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Microsoft.AspNetCore.OData/Query/ODataQueryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ private IDictionary<string, string> GetODataQueryParameters()
}
else
{
if (IsSupportedQueryOption(key))
if (!string.IsNullOrEmpty(key) && IsSupportedQueryOption(key))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it acceptable for the OData endpoint to allow an empty or whitespace-only query option, such as:
GET http://server/service/Customers?%20

Throwing an exception in this case seems reasonable.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @WanjohiSammy. I think avoiding the throw is the right choice here, since this is something a client can trigger and it currently results in an internal server error in the controller action, which doesn’t feel appropriate. This also makes the behavior consistent with EnableNoDollarQueryOptions = false, where unknown or empty keys are already ignored.

{
// Normalized the supported system query key by adding the $-prefix if needed.
result.Add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,27 @@ public async Task DuplicateUnsupportedQueryParametersIgnoredWithNoException()
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}

[Theory]
[InlineData("$top=10&$skip=0&%20")]
[InlineData("$top=10&%20=foo&$skip=0")]
[InlineData("$top=10&$skip=0&")]
[InlineData("$top=10&&$skip=0")]
[InlineData("%20")]
public void ODataQueryOptions_CtorDoesNotThrowOnEmptyQueryStringKeys(string oDataQuery)
{
// Arrange
IEdmModel model = GetEdmModelWithoutKey();

string url = "http://server/service/Customers?" + oDataQuery;
HttpRequest request = RequestFactory.Create(HttpMethods.Get, url, opt => opt.EnableNoDollarQueryOptions = true);

// Act
var exception = Record.Exception(() => new ODataQueryOptions(new ODataQueryContext(model, typeof(Customer)), request));

// Assert
Assert.Null(exception);
}

private static HttpClient CreateClient()
{
var controllers = new[] { typeof(EntityModelsController), typeof(ProductsController) };
Expand Down