You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When :hashids route constraint is not applied, the HashidsModelBinder returns
Task.CompletedTask
when the Decode method returns empty array which leads to having a default value in the route parameter - default for int is 0. Also, the model binder nor the route constraint is respecting the AcceptNonHashedIds option
I expect to have validation whether the Hash ID is valid and can be decoded - similar to when using Guid as parameter, if the :guid route constraint is not applied a 400 Bad request with validation body is returned.
Current Behavior
Currently. the model binder assumes that the route constraint would make sure that the hash can be decoded and if it cannot be, it will return a
Task.CompletedTask
thus leading to a default value for the route parameter - 0 for ints
Possible Solution
I suggest to have the same behavior as when using Guid id as route parameter - return 400 Bad request. When the :hashids route constraint is applied, the current behavior is expected.
Steps to Reproduce
[HttpGet("{id}")]
public async Task<IActionResult> GetWeatherForecast1([ModelBinder(typeof(HashidsModelBinder))] int id)
{
.
. // "id" would be 0 here when the Hash ID string cannot be decoded
.
}
Context (Environment)
.NET version: ASP.NET Core 6.0 - basic API controller
AspNetCore.Hashids version: 2.0.0
Hashids.net version: 1.6.1
Possible Implementation
/
The text was updated successfully, but these errors were encountered:
When
:hashids
route constraint is not applied, theHashidsModelBinder
returnswhen the
Decode
method returns empty array which leads to having a default value in the route parameter - default forint
is 0. Also, the model binder nor the route constraint is respecting theAcceptNonHashedIds
optionhttps://github.com/Xabaril/AspNetCore.Hashids/blob/2b5a623d10c5a5571fa99a282305977a9ecd2a15/src/AspNetCore.Hashids/Mvc/HashidsModelBinder.cs#LL44C13-L47C14
Expected Behavior
I expect to have validation whether the Hash ID is valid and can be decoded - similar to when using
Guid
as parameter, if the:guid
route constraint is not applied a 400 Bad request with validation body is returned.Current Behavior
Currently. the model binder assumes that the route constraint would make sure that the hash can be decoded and if it cannot be, it will return a
thus leading to a default value for the route parameter - 0 for
int
sPossible Solution
I suggest to have the same behavior as when using
Guid id
as route parameter - return 400 Bad request. When the:hashids
route constraint is applied, the current behavior is expected.Steps to Reproduce
Context (Environment)
.NET version: ASP.NET Core 6.0 - basic API controller
AspNetCore.Hashids version: 2.0.0
Hashids.net version: 1.6.1
Possible Implementation
/
The text was updated successfully, but these errors were encountered: