From be41ba66700e46503001dfb4c2c87f9b2aad21c6 Mon Sep 17 00:00:00 2001 From: Melanie Date: Sun, 27 Dec 2009 21:46:16 +0000 Subject: [PATCH] Allow lists to be embedded in query strings --- OpenSim/Server/Base/ServerUtils.cs | 65 +++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 11 deletions(-) diff --git a/OpenSim/Server/Base/ServerUtils.cs b/OpenSim/Server/Base/ServerUtils.cs index 413a078063..a5d28a413d 100644 --- a/OpenSim/Server/Base/ServerUtils.cs +++ b/OpenSim/Server/Base/ServerUtils.cs @@ -180,7 +180,31 @@ namespace OpenSim.Server.Base if (elems.Length > 1) value = System.Web.HttpUtility.UrlDecode(elems[1]); - result[name] = value; + if (name.EndsWith("[]")) + { + if (result.ContainsKey(name)) + { + if (!(result[name] is List)) + continue; + + List l = (List)result[name]; + + l.Add(value); + } + else + { + List newList = new List(); + + newList.Add(value); + + result[name] = newList; + } + } + else + { + if (!result.ContainsKey(name)) + result[name] = value; + } } return result; @@ -190,23 +214,42 @@ namespace OpenSim.Server.Base { string qstring = String.Empty; + string part; + foreach (KeyValuePair kvp in data) { - string part; - if (kvp.Value.ToString() != String.Empty) + if (kvp.Value is List) { - part = System.Web.HttpUtility.UrlEncode(kvp.Key) + - "=" + System.Web.HttpUtility.UrlEncode(kvp.Value.ToString()); + List l = (List)kvp.Value; + + foreach (string s in l) + { + part = System.Web.HttpUtility.UrlEncode(kvp.Key) + + "[]=" + System.Web.HttpUtility.UrlEncode(s); + + if (qstring != String.Empty) + qstring += "&"; + + qstring += part; + } } else { - part = System.Web.HttpUtility.UrlEncode(kvp.Key); + if (kvp.Value.ToString() != String.Empty) + { + part = System.Web.HttpUtility.UrlEncode(kvp.Key) + + "=" + System.Web.HttpUtility.UrlEncode(kvp.Value.ToString()); + } + else + { + part = System.Web.HttpUtility.UrlEncode(kvp.Key); + } + + if (qstring != String.Empty) + qstring += "&"; + + qstring += part; } - - if (qstring != String.Empty) - qstring += "&"; - - qstring += part; } return qstring;