Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ namespace Microsoft.AspNetCore.Http.Validation;

internal sealed class RuntimeValidatableParameterInfoResolver : IValidatableInfoResolver
{
// TODO: the implementation currently relies on static discovery of types.
// TODO: The implementation currently relies on static discovery of types.
// See https://github.com/dotnet/aspnetcore/issues/61220
public bool TryGetValidatableTypeInfo(Type type, [NotNullWhen(true)] out IValidatableInfo? validatableInfo)
{
validatableInfo = null;
Expand Down Expand Up @@ -76,17 +77,7 @@ private static bool IsClass(Type type)
{
// Skip primitives, enums, common built-in types, and types that are specially
// handled by RDF/RDG that don't need validation if they don't have attributes
if (type.IsPrimitive ||
type.IsEnum ||
type == typeof(string) ||
type == typeof(decimal) ||
type == typeof(DateTime) ||
type == typeof(DateTimeOffset) ||
type == typeof(TimeOnly) ||
type == typeof(DateOnly) ||
type == typeof(TimeSpan) ||
type == typeof(Guid) ||
type == typeof(IFormFile) ||
if (type == typeof(IFormFile) ||
type == typeof(IFormFileCollection) ||
type == typeof(IFormCollection) ||
type == typeof(HttpContext) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,8 @@ public void TryGetValidatableParameterInfo_WithNullName_ThrowsInvalidOperationEx
}

[Theory]
[InlineData(typeof(string))]
[InlineData(typeof(int))]
[InlineData(typeof(bool))]
[InlineData(typeof(DateTime))]
[InlineData(typeof(Guid))]
[InlineData(typeof(decimal))]
[InlineData(typeof(DayOfWeek))] // Enum
[InlineData(typeof(ClaimsPrincipal))]
[InlineData(typeof(PipeReader))]
[InlineData(typeof(DateTimeOffset))]
[InlineData(typeof(TimeOnly))]
[InlineData(typeof(DateOnly))]
[InlineData(typeof(TimeSpan))]
[InlineData(typeof(IFormFile))]
[InlineData(typeof(IFormFileCollection))]
[InlineData(typeof(IFormCollection))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public async Task CanValidateParameters()
[CustomValidation, Range(10, 100)] int value5 = 10,
// Skipped from validation because it is marked as a [FromService] parameter
[FromServices] [Range(10, 100)] int? value6 = 4,
[MinLength(7)] string? value7 = "LongEnough",
Dictionary<string, TestService>? testDict = null) => "OK");

app.Run();
Expand All @@ -59,7 +60,7 @@ public class TestService
await VerifyEndpoint(compilation, "/params", async (endpoint, serviceProvider) =>
{
var context = CreateHttpContext(serviceProvider);
context.Request.QueryString = new QueryString("?value1=5&value2=5&value3=&value4=3&value5=5");
context.Request.QueryString = new QueryString("?value1=5&value2=5&value3=&value4=3&value5=5&value7=Short");
await endpoint.RequestDelegate(context);
var problemDetails = await AssertBadRequest(context);
Assert.Collection(problemDetails.Errors,
Expand Down Expand Up @@ -94,6 +95,11 @@ await VerifyEndpoint(compilation, "/params", async (endpoint, serviceProvider) =
{
Assert.Equal("The field value5 must be between 10 and 100.", error);
});
},
error =>
{
Assert.Equal("value7", error.Key);
Assert.Equal("The field value7 must be a string or array type with a minimum length of '7'.", error.Value.Single());
});
});
}
Expand Down
Loading