#130 - Remove semi-colon support from query parsing.

This commit is contained in:
Chris Ross 2014-10-08 14:25:59 -07:00
parent 20de1d0597
commit f5577c589e
2 changed files with 5 additions and 14 deletions

View File

@ -68,7 +68,7 @@ namespace Microsoft.AspNet.WebUtilities
{
IDictionary<string, string[]> form = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);
var accumulator = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
ParseDelimited(text, new[] { '&' }, AppendItemCallback, accumulator);
ParseDelimited(text, Ampersand, AppendItemCallback, accumulator);
foreach (var kv in accumulator)
{
form.Add(kv.Key, kv.Value.ToArray());
@ -92,7 +92,7 @@ namespace Microsoft.AspNet.WebUtilities
return store.TryGetValue(key, out values) ? values : null;
}
private static readonly char[] AmpersandAndSemicolon = new[] { '&', ';' };
private static readonly char[] Ampersand = new[] { '&' };
internal static IReadableStringCollection GetQuery(string queryString)
{
@ -101,7 +101,7 @@ namespace Microsoft.AspNet.WebUtilities
queryString = queryString.Substring(1);
}
var accumulator = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
ParseDelimited(queryString, AmpersandAndSemicolon, AppendItemCallback, accumulator);
ParseDelimited(queryString, Ampersand, AppendItemCallback, accumulator);
return new ReadableStringCollection(accumulator.ToDictionary(
item => item.Key,
item => item.Value.ToArray(),

View File

@ -35,19 +35,10 @@ namespace Microsoft.AspNet.WebUtilities
Assert.Equal("valueB", collection["key2"]);
}
[Fact]
public void ParseQueryWithSemicolonWorks()
{
var collection = QueryHelpers.ParseQuery("?key1=value1;key2=value2");
Assert.Equal(2, collection.Count);
Assert.Equal("value1", collection["key1"]);
Assert.Equal("value2", collection["key2"]);
}
[Fact]
public void ParseQueryWithEmptyValuesWorks()
{
var collection = QueryHelpers.ParseQuery("?key1=;key2=");
var collection = QueryHelpers.ParseQuery("?key1=&key2=");
Assert.Equal(2, collection.Count);
Assert.Equal(string.Empty, collection["key1"]);
Assert.Equal(string.Empty, collection["key2"]);
@ -56,7 +47,7 @@ namespace Microsoft.AspNet.WebUtilities
[Fact]
public void ParseQueryWithEmptyKeyWorks()
{
var collection = QueryHelpers.ParseQuery("?=value1;=");
var collection = QueryHelpers.ParseQuery("?=value1&=");
Assert.Equal(1, collection.Count);
Assert.Equal("value1,", collection[""]);
}