Skip to content

Bugfix/exact match empty query #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
@@ -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);
7 changes: 6 additions & 1 deletion RichardSzalay.MockHttp/Matchers/QueryStringMatcher.cs
Original file line number Diff line number Diff line change
@@ -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]),