Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed routes with CatchAll argument, in order to make them succesfully

match requests with empty (or null) catch-all portion.

Included a couple of unit-tests which pass both here, and on ms.net land.

License: This patch is under MIT/X11 license.
  • Loading branch information...
commit 3ce598d0a18514086dbc44bb71e3f64b1d0a5843 1 parent 00b8180
@pruiz authored
View
4 mcs/class/System.Web.Routing/System.Web.Routing/PatternParser.cs
@@ -352,6 +352,10 @@ public RouteValueDictionary Match (string path, RouteValueDictionary defaults)
if (tokens.Count != 1)
return null;
+ // if token is catch-all, we're done.
+ if (tokens [0].Type == PatternTokenType.CatchAll)
+ break;
+
if (!defaults.ContainsKey (tokens [0].Name))
return null;
}
View
4 mcs/class/System.Web.Routing/Test/System.Web.Routing/RouteCollectionTest.cs
@@ -595,6 +595,10 @@ public void GetVirtualPath8()
Assert.IsNotNull(vpd, "#C1");
Assert.AreEqual("/", vpd.VirtualPath, "#C2");
Assert.AreEqual(0, vpd.DataTokens.Count, "#C3");
+
+ hc = new HttpContextStub2("~/", String.Empty, String.Empty);
+ rd = routes.GetRouteData(hc);
+ Assert.IsNotNull(rd, "#D1");
}
[Test]
View
64 mcs/class/System.Web.Routing/Test/System.Web.Routing/RouteTest.cs
@@ -974,12 +974,72 @@ public void GetRouteData47 ()
})
};
- var hc = new HttpContextStub ("/Foo/x123", String.Empty);
+ var hc = new HttpContextStub ("~/Foo/x123", String.Empty);
var rd = r.GetRouteData (hc);
Assert.IsNull (rd, "#1");
}
-
+
+ [Test]
+ public void GetRouteDataWithCatchAll()
+ {
+ var r = new Route("{*path}", new StopRoutingHandler())
+ {
+ Defaults = new RouteValueDictionary(new
+ {
+ controller = "Error",
+ action = "NotFound"
+ })
+ };
+
+ var hc = new HttpContextStub("~/", String.Empty);
+ var rd = r.GetRouteData(hc);
+
+ Assert.IsNotNull(rd, "#1");
+
+ hc = new HttpContextStub("~/Foo/x123", String.Empty);
+ rd = r.GetRouteData(hc);
+
+ Assert.IsNotNull(rd, "#2");
+ }
+
+ [Test]
+ public void GetRouteDataWithCatchAll2()
+ {
+ var r = new Route("something/{*path}", new StopRoutingHandler())
+ {
+ Defaults = new RouteValueDictionary(new
+ {
+ controller = "Error",
+ action = "NotFound"
+ })
+ };
+
+ var hc = new HttpContextStub("~/", String.Empty);
+ var rd = r.GetRouteData(hc);
+
+ Assert.IsNull(rd, "#1");
+
+ hc = new HttpContextStub("~/something", String.Empty);
+ rd = r.GetRouteData(hc);
+
+ Assert.IsNotNull(rd, "#2");
+ Assert.IsNull(rd.Values["path"], "#2.1");
+
+ hc = new HttpContextStub("~/something/", String.Empty);
+ rd = r.GetRouteData(hc);
+
+ Assert.IsNotNull(rd, "#3");
+ Assert.IsNull(rd.Values["path"], "#3.1");
+
+ hc = new HttpContextStub("~/something/algo", String.Empty);
+ rd = r.GetRouteData(hc);
+
+ Assert.IsNotNull(rd, "#4");
+ Assert.AreEqual("algo", rd.Values["path"], "#4.1");
+
+ }
+
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void GetVirtualPathNullContext ()
Please sign in to comment.
Something went wrong with that request. Please try again.