From 123eaf2278072df584eb4fbdee5224790b8af458 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Mon, 30 Nov 2015 09:28:15 -0800 Subject: [PATCH] Fix #233 - Routing stops when constraint is rejected The fix here is to 'continue' instead of 'return'. Added the relevant test cases, which only had positive cases for constraints. --- .../AttributeRouting/TreeRouter.cs | 2 +- .../AttributeRouting/TreeRouterTest.cs | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Routing/AttributeRouting/TreeRouter.cs b/src/Microsoft.AspNet.Routing/AttributeRouting/TreeRouter.cs index 70163d2280..7aa8a65333 100644 --- a/src/Microsoft.AspNet.Routing/AttributeRouting/TreeRouter.cs +++ b/src/Microsoft.AspNet.Routing/AttributeRouting/TreeRouter.cs @@ -190,7 +190,7 @@ namespace Microsoft.AspNet.Routing.Tree RouteDirection.IncomingRequest, _constraintLogger)) { - return; + continue; } _logger.MatchedRouteName(match.Entry.RouteName, match.Entry.RouteTemplate.TemplateText); diff --git a/test/Microsoft.AspNet.Routing.Tests/AttributeRouting/TreeRouterTest.cs b/test/Microsoft.AspNet.Routing.Tests/AttributeRouting/TreeRouterTest.cs index 38c82a4b69..e378206e60 100644 --- a/test/Microsoft.AspNet.Routing.Tests/AttributeRouting/TreeRouterTest.cs +++ b/test/Microsoft.AspNet.Routing.Tests/AttributeRouting/TreeRouterTest.cs @@ -22,6 +22,7 @@ namespace Microsoft.AspNet.Routing.Tree [InlineData("template/5", "template/{parameter}")] [InlineData("template/5", "template/{*parameter:int}")] [InlineData("template/5", "template/{*parameter}")] + [InlineData("template/{parameter}", "template/{parameter:alpha}")] // constraint doesn't match [InlineData("template/{parameter:int}", "template/{parameter}")] [InlineData("template/{parameter:int}", "template/{*parameter:int}")] [InlineData("template/{parameter:int}", "template/{*parameter}")] @@ -203,7 +204,9 @@ namespace Microsoft.AspNet.Routing.Tree [InlineData("template/{parameter:int?}", "/template", true)] [InlineData("template/{parameter:int?}", "/template/qwer", false)] public async Task AttributeRoute_WithOptionalInlineConstraint( - string template, string request, bool expectedResult) + string template, + string request, + bool expectedResult) { // Arrange var expectedRouteGroup = string.Format("{0}&&{1}", 0, template); @@ -365,6 +368,7 @@ namespace Microsoft.AspNet.Routing.Tree [InlineData("{id}", "{*url}", "/5?url=dingo")] [InlineData("{id}", "{*url:alpha}", "/5?url=dingo")] [InlineData("{id:int}", "{id}", "/5?url=dingo")] + [InlineData("{id}", "{id:alpha}/{url}", "/5?url=dingo")] // constraint doesn't match [InlineData("template/api/{*url}", "template/api", "/template/api/dingo?id=5")] [InlineData("template/api", "template/{*url}", "/template/api?url=dingo&id=5")] [InlineData("template/api", "template/api{id}location", "/template/api?url=dingo&id=5")] @@ -581,8 +585,10 @@ namespace Microsoft.AspNet.Routing.Tree [InlineData("template/{parameter:int:range(1,20)?}", "/template", null)] [InlineData("template/{parameter:int:range(1,20)?}", "/template/5", 5)] [InlineData("template/{parameter:int:range(1,20)?}", null, 21)] - public void AttributeRoute_GenerateLink_OptionalInlineParameter - (string template, string expectedPath, object parameter) + public void AttributeRoute_GenerateLink_OptionalInlineParameter( + string template, + string expectedPath, + object parameter) { // Arrange var expectedGroup = CreateRouteGroup(0, template);