Skip to content

Poor handling of malformed route - Index was outside the bounds of the array. #287

Description

@dotnetchris

If you have a malformed AttributeRouting Route you get a very ungraceful error.

Suppose i have the route:

[GET("contents/{page-slug}/{blog-title")]

Note the lack of a closing } on blog-title.

This results in the exception

[IndexOutOfRangeException: Index was outside the bounds of the array.]
   AttributeRouting.Framework.RouteBuilder.RemoveQueryString(String url) +149
   AttributeRouting.Framework.RouteBuilder.CreateRouteDefaults(RouteSpecification routeSpec, IDictionary`2& defaults, IDictionary`2& queryStringDefaults) +296
   AttributeRouting.Framework.<BuildRoutes>d__4.MoveNext() +143
   System.Linq.<SelectManyIterator>d__14`2.MoveNext() +507
   System.Linq.<CastIterator>d__b1`1.MoveNext() +296
   System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +536
   System.Linq.Enumerable.ToList(IEnumerable`1 source) +80
   AttributeRouting.Web.Mvc.RouteCollectionExtensions.MapAttributeRoutesInternal(RouteCollection routes, Configuration configuration) +104
   Web.Site.AttributeRoutingConfig.RegisterRoutes(RouteCollection routes) in c:\Projects\myproj\src\Site\App_Start\AttributeRoutingConfig.cs:15
   Web.Site.AttributeRoutingConfig.Start() in c:\Projects\myproj\src\Site\App_Start\AttributeRoutingConfig.cs:20

This exception makes no sense to a user of AR. I have a route with no query string, why am i blowing up in RemoveQueryString?

I understand it might be very difficult to build a parser that verifies the string is valid. At the very least i think you need to do boundary checking in RemoveQueryString and throw a MalformedRouteException() or PossiblyMalformedRouteException() etc.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions