Merge pull request #226 from petejohanson/uri-templates-unprefixed-wildcard
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Sun, 19 Feb 2012 17:08:57 +0000 (09:08 -0800)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Sun, 19 Feb 2012 17:08:57 +0000 (09:08 -0800)
Fix Bug #658, allowing uri templates with no text preceding a wildcard.

mcs/class/System.ServiceModel.Web/System/UriTemplate.cs
mcs/class/System.ServiceModel.Web/Test/System/UriTemplateTest.cs

index 177e860c07359da66499f7c3a8d09e57c2b39fff..c1c0018ceae111d06ed5571ac0de0582669f54c3 100644 (file)
@@ -303,7 +303,7 @@ namespace System
                        if (tEnd < 0)
                                tEnd = template.Length;
                        if (wild)
-                               tEnd = wildIdx - 1;
+                               tEnd = Math.Max (wildIdx - 1, 0);
                        if (!wild && (cp.Length - c) != (tEnd - i) ||
                            String.CompareOrdinal (cp, c, template, i, tEnd - i) != 0)
                                return null; // suffix doesn't match
index b72f2ff04af442649bb3ba6e02fde924b148909a..8455ce59340f4bfe89e540b7f17811b9a3331203 100644 (file)
@@ -425,6 +425,32 @@ namespace MonoTests.System
                        Assert.AreEqual ("qqq", m.WildcardPathSegments [1], "#4");
                }
 
+               [Test]
+               public void MatchWildcard2 ()
+               {
+                       var t = new UriTemplate ("*");
+                       var m = t.Match (new Uri ("http://localhost"), new Uri ("http://localhost/hoge/ppp"));
+                       Assert.IsNotNull (m, "#0");
+                       Assert.IsEmpty (m.QueryParameters, "#1.0");
+                       Assert.AreEqual ("hoge", m.WildcardPathSegments [0], "#2");
+                       Assert.AreEqual ("ppp", m.WildcardPathSegments [1], "#3");
+               }
+
+               [Test]
+               public void MatchWildcard3 ()
+               {
+                       var t = new UriTemplate ("*?p1={foo}");
+                       var m = t.Match (new Uri ("http://localhost"), new Uri ("http://localhost/hoge/ppp/qqq?p1=v1"));
+                       Assert.IsNotNull (m, "#0");
+                       Assert.IsNotNull (m.QueryParameters, "#1.0");
+                       Assert.AreEqual ("v1", m.QueryParameters ["p1"], "#1");
+                       Assert.IsNotNull (m.WildcardPathSegments, "#2.0");
+                       Assert.AreEqual (3, m.WildcardPathSegments.Count, "#2");
+                       Assert.AreEqual ("hoge", m.WildcardPathSegments [0], "#3");
+                       Assert.AreEqual ("ppp", m.WildcardPathSegments [1], "#4");
+                       Assert.AreEqual ("qqq", m.WildcardPathSegments [2], "#5");
+               }
+
                [Test]
                public void IgnoreTrailingSlash ()
                {