-
-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Add some basic input validation to the templates. Would not only prevent Piranha from crashing if invalid input is made but also provide a good example of how to do it.
For instance, an invalid e-mail address of a comment will cause an exception that will crash the application. I assume this is the proper behavior of Piranha.Core but it would be both pedagogical and better if application/templates won't crash upon quite normal 'misbehavior' of a site visitor.
Steps to reproduce the exception:
- Create a new project from Razor Template
- Run the project and enter an invalid (ie 'ThisIsAnInvalidEmailAdress') e-mail address on any comment and submit it
Output of application:
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
System.ComponentModel.DataAnnotations.ValidationException: The Email field is not a valid e-mail address.
at System.ComponentModel.DataAnnotations.Validator.ValidationError.ThrowValidationException()
at System.ComponentModel.DataAnnotations.Validator.ValidateObject(Object instance, ValidationContext validationContext, Boolean validateAllProperties)
at Piranha.Services.PostService.SaveCommentAsync(Guid postId, Comment model, Boolean verify)
at Piranha.AspNetCore.Models.SinglePostWithComments`1.OnPostSaveComment(Guid id, Boolean draft)
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory.GenericTaskHandlerMethod.Convert[T](Object taskAsObject)
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory.GenericTaskHandlerMethod.Execute(Object receiver, Object[] arguments)
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeHandlerMethodAsync()
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeNextPageFilterAsync()
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Rethrow(PageHandlerExecutedContext context)
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeInnerFilterAsync()
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Piranha.AspNetCore.SitemapMiddleware.Invoke(HttpContext context, IApi api, IApplicationService service)
at Piranha.AspNetCore.IntegratedMiddleware.Invoke(HttpContext context, IApi api, IApplicationService service)
at Piranha.AspNetCore.Security.SecurityMiddleware.InvokeAsync(HttpContext ctx, IApplicationService service)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request