Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dotnetchris opened this issue Apr 29, 2014 · 0 comments

Comments

@dotnetchris
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant