#130 - Remove semi-colon support from query parsing.
This commit is contained in:
parent
20de1d0597
commit
f5577c589e
|
|
@ -68,7 +68,7 @@ namespace Microsoft.AspNet.WebUtilities
|
||||||
{
|
{
|
||||||
IDictionary<string, string[]> form = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);
|
IDictionary<string, string[]> form = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);
|
||||||
var accumulator = new Dictionary<string, List<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)
|
foreach (var kv in accumulator)
|
||||||
{
|
{
|
||||||
form.Add(kv.Key, kv.Value.ToArray());
|
form.Add(kv.Key, kv.Value.ToArray());
|
||||||
|
|
@ -92,7 +92,7 @@ namespace Microsoft.AspNet.WebUtilities
|
||||||
return store.TryGetValue(key, out values) ? values : null;
|
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)
|
internal static IReadableStringCollection GetQuery(string queryString)
|
||||||
{
|
{
|
||||||
|
|
@ -101,7 +101,7 @@ namespace Microsoft.AspNet.WebUtilities
|
||||||
queryString = queryString.Substring(1);
|
queryString = queryString.Substring(1);
|
||||||
}
|
}
|
||||||
var accumulator = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
|
var accumulator = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
|
||||||
ParseDelimited(queryString, AmpersandAndSemicolon, AppendItemCallback, accumulator);
|
ParseDelimited(queryString, Ampersand, AppendItemCallback, accumulator);
|
||||||
return new ReadableStringCollection(accumulator.ToDictionary(
|
return new ReadableStringCollection(accumulator.ToDictionary(
|
||||||
item => item.Key,
|
item => item.Key,
|
||||||
item => item.Value.ToArray(),
|
item => item.Value.ToArray(),
|
||||||
|
|
|
||||||
|
|
@ -35,19 +35,10 @@ namespace Microsoft.AspNet.WebUtilities
|
||||||
Assert.Equal("valueB", collection["key2"]);
|
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]
|
[Fact]
|
||||||
public void ParseQueryWithEmptyValuesWorks()
|
public void ParseQueryWithEmptyValuesWorks()
|
||||||
{
|
{
|
||||||
var collection = QueryHelpers.ParseQuery("?key1=;key2=");
|
var collection = QueryHelpers.ParseQuery("?key1=&key2=");
|
||||||
Assert.Equal(2, collection.Count);
|
Assert.Equal(2, collection.Count);
|
||||||
Assert.Equal(string.Empty, collection["key1"]);
|
Assert.Equal(string.Empty, collection["key1"]);
|
||||||
Assert.Equal(string.Empty, collection["key2"]);
|
Assert.Equal(string.Empty, collection["key2"]);
|
||||||
|
|
@ -56,7 +47,7 @@ namespace Microsoft.AspNet.WebUtilities
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ParseQueryWithEmptyKeyWorks()
|
public void ParseQueryWithEmptyKeyWorks()
|
||||||
{
|
{
|
||||||
var collection = QueryHelpers.ParseQuery("?=value1;=");
|
var collection = QueryHelpers.ParseQuery("?=value1&=");
|
||||||
Assert.Equal(1, collection.Count);
|
Assert.Equal(1, collection.Count);
|
||||||
Assert.Equal("value1,", collection[""]);
|
Assert.Equal("value1,", collection[""]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue