Skip to content
Browse files

Fix for bug #4896: Incorrect routing of catchall parameter

  • Loading branch information...
1 parent 5c61004 commit 65f7b4a137cc45d8c666669a9343953f5f415aa4 @thephred thephred committed
View
11 mcs/class/System.Web.Routing/System.Web.Routing/PatternParser.cs
@@ -219,12 +219,13 @@ bool MatchSegment (int segIndex, int argsCount, string[] argSegs, List <PatternT
for (int tokenIndex = tokensCount - 1; tokenIndex > -1; tokenIndex--) {
token = tokens [tokenIndex];
- if (startIndex < 0)
- return false;
-
tokenType = token.Type;
tokenName = token.Name;
+ if (startIndex < 0 && tokenType != PatternTokenType.CatchAll)
+ return false;
+
+
if (segIndex > segmentCount - 1 || tokenType == PatternTokenType.CatchAll) {
var sb = new StringBuilder ();
@@ -303,8 +304,8 @@ public RouteValueDictionary Match (string path, RouteValueDictionary defaults)
argSegs = path.Split ('/');
argsCount = argSegs.Length;
- if (String.IsNullOrEmpty (argSegs [argsCount - 1]))
- argsCount--; // path ends with a trailinig '/'
+ if (String.IsNullOrEmpty (argSegs [argsCount - 1]) && !haveSegmentWithCatchAll)
+ argsCount--; // path ends with a trailing '/'
}
bool haveDefaults = defaults != null && defaults.Count > 0;
View
16 mcs/class/System.Web.Routing/Test/System.Web.Routing/RouteTest.cs
@@ -979,7 +979,21 @@ public void GetRouteData47 ()
Assert.IsNull (rd, "#1");
}
-
+
+ [Test]
+ public void GetRouteData48 ()
+ {
+ var r = new Route ("{first}/{*rest}", null);
+ var hc = new HttpContextStub ("~/a/", String.Empty);
+ var rd = r.GetRouteData (hc);
+ Assert.IsNotNull (rd, "#1");
+ Assert.AreEqual (r, rd.Route, "#2");
+ Assert.AreEqual (0, rd.DataTokens.Count, "#3");
+ Assert.AreEqual (2, rd.Values.Count, "#4");
+ Assert.AreEqual ("a", rd.Values ["first"], "#4-1");
+ Assert.AreEqual (String.Empty, rd.Values ["rest"], "#4-2"
+ }
+
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void GetVirtualPathNullContext ()

0 comments on commit 65f7b4a

Please sign in to comment.
Something went wrong with that request. Please try again.