Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions RichardSzalay.MockHttp.Tests/Matchers/QueryStringMatcherTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ public void Should_support_matching_dictionary_data_with_url_encoded_values()
Assert.True(actualMatch, "QueryStringMatcher.Matches() should match dictionary data with URL encoded query string values.");
}

[Fact]
public void Should_support_matching_with_empty_dictionary_data_when_exact_is_true()
{
var data = new Dictionary<string, string>();

var sut = new QueryStringMatcher(data, true);

var actualMatch = sut.Matches(new HttpRequestMessage(HttpMethod.Get, "http://tempuri.org/home"));

Assert.True(actualMatch, "QueryStringMatcher.Matches() should match empty dictionary data.");
}

private bool Test(string expected, string actual, bool exact = false)
{
var sut = new QueryStringMatcher(expected, exact);
Expand Down
7 changes: 6 additions & 1 deletion RichardSzalay.MockHttp/Matchers/QueryStringMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ public bool Matches(System.Net.Http.HttpRequestMessage message)

internal static IEnumerable<KeyValuePair<string, string>> ParseQueryString(string input)
{
return input.TrimStart('?').Split('&')
if (input.Length == 0)
{
return Enumerable.Empty<KeyValuePair<string, string>>();
}
return input.TrimStart('?')
.Split('&')
.Select(pair => StringUtil.Split(pair, '=', 2))
.Select(pair => new KeyValuePair<string, string>(
UrlDecode(pair[0]),
Expand Down