Merge pull request #1542 from ninjarobot/UriTemplateMatchException
authorMiguel de Icaza <miguel@gnome.org>
Mon, 16 Feb 2015 15:19:44 +0000 (10:19 -0500)
committerMiguel de Icaza <miguel@gnome.org>
Mon, 16 Feb 2015 15:19:44 +0000 (10:19 -0500)
Fix to UriTemplate.Match to properly handle query parameters without a v...

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

index 875acb2117ec61a67808e9e4c99958795ec84a7f..b72c14c4324db300f91f9bdaa6ca2837d0294564 100644 (file)
@@ -321,11 +321,15 @@ namespace System
                        string [] parameters = Uri.UnescapeDataString (candidate.Query.Substring (1)).Split ('&'); // chop first '?'
                        foreach (string parameter in parameters) {
                                string [] pair = parameter.Split ('=');
-                               m.QueryParameters.Add (pair [0], pair [1]);
-                               if (!query_params.ContainsKey (pair [0]))
-                                       continue;
-                               string templateName = query_params [pair [0]];
-                               vc.Add (templateName, pair [1]);
+                               if (pair.Length > 0) {
+                                       m.QueryParameters.Add (pair [0], pair.Length == 2 ? pair [1] : null);
+                                       if (!query_params.ContainsKey (pair [0]))
+                                               continue;
+                                       if (pair.Length > 1) {
+                                               string templateName = query_params [pair [0]];
+                                               vc.Add (templateName, pair [1]);
+                                       }
+                               }
                        }
 
                        return m;
index 24ec92861d82a1bc9d6f8e4a8202a6f6dd9ec5b0..361921ddcfcbbfc17d6959310ab30975201a115e 100644 (file)
@@ -461,6 +461,14 @@ namespace MonoTests.System
                        Assert.AreEqual ("qqq", m.WildcardPathSegments [2], "#5");
                }
 
+               [Test]
+               public void MatchIgnoreQueryParamNoValue ()
+               {
+                       var t = new UriTemplate ("/{a}/*", true);
+                       var m = t.Match (new Uri ("http://s"), new Uri ("http://s/a/b?foo"));
+                       Assert.AreEqual (1, m.QueryParameters.Keys.Count, "#1");
+               }
+
                [Test]
                public void IgnoreTrailingSlash ()
                {