parent
440c6e43e1
commit
e854d3aa9a
|
|
@ -140,7 +140,6 @@ namespace Microsoft.AspNetCore.WebUtilities
|
||||||
scanIndex = 1;
|
scanIndex = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int textLength = queryString.Length;
|
int textLength = queryString.Length;
|
||||||
int equalIndex = queryString.IndexOf('=');
|
int equalIndex = queryString.IndexOf('=');
|
||||||
if (equalIndex == -1)
|
if (equalIndex == -1)
|
||||||
|
|
@ -171,6 +170,13 @@ namespace Microsoft.AspNetCore.WebUtilities
|
||||||
equalIndex = textLength;
|
equalIndex = textLength;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (delimiterIndex > scanIndex)
|
||||||
|
{
|
||||||
|
accumulator.Append(queryString.Substring(scanIndex, delimiterIndex - scanIndex), string.Empty);
|
||||||
|
}
|
||||||
|
}
|
||||||
scanIndex = delimiterIndex + 1;
|
scanIndex = delimiterIndex + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,5 +24,44 @@ namespace Microsoft.AspNetCore.Http.Features
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal("bar", queryCollection["foo"]);
|
Assert.Equal("bar", queryCollection["foo"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("?q", "q")]
|
||||||
|
[InlineData("?q&", "q")]
|
||||||
|
[InlineData("?q1=abc&q2", "q2")]
|
||||||
|
[InlineData("?q=", "q")]
|
||||||
|
[InlineData("?q=&", "q")]
|
||||||
|
public void KeyWithoutValuesAddedToQueryCollection(string queryString, string emptyParam)
|
||||||
|
{
|
||||||
|
var features = new FeatureCollection();
|
||||||
|
var request = new HttpRequestFeature();
|
||||||
|
request.QueryString = queryString;
|
||||||
|
features[typeof(IHttpRequestFeature)] = request;
|
||||||
|
|
||||||
|
var provider = new QueryFeature(features);
|
||||||
|
|
||||||
|
var queryCollection = provider.Query;
|
||||||
|
|
||||||
|
Assert.True(queryCollection.Keys.Contains(emptyParam));
|
||||||
|
Assert.Equal(string.Empty, queryCollection[emptyParam]);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("?&&")]
|
||||||
|
[InlineData("?&")]
|
||||||
|
[InlineData("&&")]
|
||||||
|
public void EmptyKeysNotAddedToQueryCollection(string queryString)
|
||||||
|
{
|
||||||
|
var features = new FeatureCollection();
|
||||||
|
var request = new HttpRequestFeature();
|
||||||
|
request.QueryString = queryString;
|
||||||
|
features[typeof(IHttpRequestFeature)] = request;
|
||||||
|
|
||||||
|
var provider = new QueryFeature(features);
|
||||||
|
|
||||||
|
var queryCollection = provider.Query;
|
||||||
|
|
||||||
|
Assert.Equal(0, queryCollection.Count);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue