diff options
author | Peter Johanson <peter@peterjohanson.com> | 2012-02-14 17:17:06 +0400 |
---|---|---|
committer | Peter Johanson <peter@peterjohanson.com> | 2012-02-14 17:17:06 +0400 |
commit | bb8d09d41d5032c18a5a28779a19591601b67d82 (patch) | |
tree | d656347ed0dabb2131153462559cb8d55d5a7af5 /mcs/class/System.ServiceModel.Web | |
parent | da3e85007e6005f11cbae70e4acecfeba15635e1 (diff) |
Fix Bug #658, allowing uri templates with no text preceding a wildcard.
Diffstat (limited to 'mcs/class/System.ServiceModel.Web')
-rw-r--r-- | mcs/class/System.ServiceModel.Web/System/UriTemplate.cs | 2 | ||||
-rw-r--r-- | mcs/class/System.ServiceModel.Web/Test/System/UriTemplateTest.cs | 26 |
2 files changed, 27 insertions, 1 deletions
diff --git a/mcs/class/System.ServiceModel.Web/System/UriTemplate.cs b/mcs/class/System.ServiceModel.Web/System/UriTemplate.cs index 177e860c073..c1c0018ceae 100644 --- a/mcs/class/System.ServiceModel.Web/System/UriTemplate.cs +++ b/mcs/class/System.ServiceModel.Web/System/UriTemplate.cs @@ -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 diff --git a/mcs/class/System.ServiceModel.Web/Test/System/UriTemplateTest.cs b/mcs/class/System.ServiceModel.Web/Test/System/UriTemplateTest.cs index b72f2ff04af..8455ce59340 100644 --- a/mcs/class/System.ServiceModel.Web/Test/System/UriTemplateTest.cs +++ b/mcs/class/System.ServiceModel.Web/Test/System/UriTemplateTest.cs @@ -426,6 +426,32 @@ namespace MonoTests.System } [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 () { var t = new UriTemplate ("/{foo}/{bar}", true); |