Skip to content

Commit 7a64b9d

Browse files
authored
Don't crash on empty query string parameter name (#1484)
1 parent 4427187 commit 7a64b9d

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Diff for: src/JsonApiDotNetCore/QueryStrings/QueryStringReader.cs

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public void ReadAll(DisableQueryStringAttribute? disableQueryStringAttribute)
3838

3939
foreach ((string parameterName, StringValues parameterValue) in _queryStringAccessor.Query)
4040
{
41+
if (parameterName.Length == 0)
42+
{
43+
continue;
44+
}
45+
4146
IQueryStringParameterReader? reader = _parameterReaders.FirstOrDefault(nextReader => nextReader.CanRead(parameterName));
4247

4348
if (reader != null)

Diff for: test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/QueryStringTests.cs

+18
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,24 @@ public async Task Can_use_unknown_query_string_parameter()
6363
httpResponse.ShouldHaveStatusCode(HttpStatusCode.OK);
6464
}
6565

66+
[Theory]
67+
[InlineData("")]
68+
[InlineData("bar")]
69+
public async Task Can_use_empty_query_string_parameter_name(string parameterValue)
70+
{
71+
// Arrange
72+
var options = (JsonApiOptions)_testContext.Factory.Services.GetRequiredService<IJsonApiOptions>();
73+
options.AllowUnknownQueryStringParameters = false;
74+
75+
string route = $"calendars?={parameterValue}";
76+
77+
// Act
78+
(HttpResponseMessage httpResponse, Document _) = await _testContext.ExecuteGetAsync<Document>(route);
79+
80+
// Assert
81+
httpResponse.ShouldHaveStatusCode(HttpStatusCode.OK);
82+
}
83+
6684
[Theory]
6785
[InlineData("filter")]
6886
[InlineData("sort")]

0 commit comments

Comments
 (0)