DotNetAnalyzers / AspNetCoreAnalyzers

MIT License
62 stars 4 forks source link

Illegal characters in route template #19

Closed JohanLarsson closed 5 years ago

JohanLarsson commented 5 years ago

https://tools.ietf.org/html/rfc3986#section-2.2 https://tools.ietf.org/html/rfc3986#section-3.3

JohanLarsson commented 5 years ago
[ApiController]
public class ValuesController : ControllerBase
{
    [HttpGet("api/values?meh/{id}")]
    public ActionResult<string> Get(string id)
    {
        return $"'{id.ToString()}'";
    }

ArgumentException: The literal section 'values?meh' is invalid. Literal sections cannot contain the '?' character. Parameter name: routeTemplate Microsoft.AspNetCore.Routing.Template.TemplateParser.Parse(string routeTemplate) Microsoft.AspNetCore.Mvc.Internal.ApiBehaviorApplicationModelProvider.ParameterExistsInAnyRoute(ActionModel actionModel, string parameterName) Microsoft.AspNetCore.Mvc.Internal.ApiBehaviorApplicationModelProvider.InferBindingSourceForParameter(ParameterModel parameter) Microsoft.AspNetCore.Mvc.Internal.ApiBehaviorApplicationModelProvider.InferParameterBindingSources(ActionModel actionModel) Microsoft.AspNetCore.Mvc.Internal.ApiBehaviorApplicationModelProvider.OnProvidersExecuting(ApplicationModelProviderContext context) Microsoft.AspNetCore.Mvc.Internal.ControllerActionDescriptorProvider.BuildModel() Microsoft.AspNetCore.Mvc.Internal.ControllerActionDescriptorProvider.GetDescriptors() Microsoft.AspNetCore.Mvc.Internal.ControllerActionDescriptorProvider.OnProvidersExecuting(ActionDescriptorProviderContext context) Microsoft.AspNetCore.Mvc.Internal.ActionDescriptorCollectionProvider.UpdateCollection() Microsoft.AspNetCore.Mvc.Internal.ActionDescriptorCollectionProvider.get_ActionDescriptors() Microsoft.AspNetCore.Mvc.Internal.AttributeRoute.GetTreeRouter() Microsoft.AspNetCore.Mvc.Internal.AttributeRoute.RouteAsync(RouteContext context) Microsoft.AspNetCore.Routing.RouteCollection.RouteAsync(RouteContext context) Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext) Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

JohanLarsson commented 5 years ago

Turns out # is valid if percent encoded.