Allow lists to be embedded in query strings

slimupdates
Melanie 2009-12-27 21:46:16 +00:00
parent 2f717fc796
commit 0f5219a004
1 changed files with 54 additions and 11 deletions

View File

@ -180,8 +180,32 @@ namespace OpenSim.Server.Base
if (elems.Length > 1) if (elems.Length > 1)
value = System.Web.HttpUtility.UrlDecode(elems[1]); value = System.Web.HttpUtility.UrlDecode(elems[1]);
if (name.EndsWith("[]"))
{
if (result.ContainsKey(name))
{
if (!(result[name] is List<string>))
continue;
List<string> l = (List<string>)result[name];
l.Add(value);
}
else
{
List<string> newList = new List<string>();
newList.Add(value);
result[name] = newList;
}
}
else
{
if (!result.ContainsKey(name))
result[name] = value; result[name] = value;
} }
}
return result; return result;
} }
@ -190,9 +214,27 @@ namespace OpenSim.Server.Base
{ {
string qstring = String.Empty; string qstring = String.Empty;
string part;
foreach (KeyValuePair<string, object> kvp in data) foreach (KeyValuePair<string, object> kvp in data)
{ {
string part; if (kvp.Value is List<string>)
{
List<string> l = (List<String>)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
{
if (kvp.Value.ToString() != String.Empty) if (kvp.Value.ToString() != String.Empty)
{ {
part = System.Web.HttpUtility.UrlEncode(kvp.Key) + part = System.Web.HttpUtility.UrlEncode(kvp.Key) +
@ -208,6 +250,7 @@ namespace OpenSim.Server.Base
qstring += part; qstring += part;
} }
}
return qstring; return qstring;
} }