Skip to content

Commit 7cd2893

Browse files
authored
Ensure WithPath works with URL-encoded characters (#51)
1 parent 04828cb commit 7cd2893

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

Mockly.Specs/HttpMockSpecs.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,45 @@ public async Task The_query_does_not_require_a_question_mark()
141141
response.StatusCode.Should().Be(HttpStatusCode.OK);
142142
}
143143

144+
[Fact]
145+
public async Task Can_match_path_with_pipe_character()
146+
{
147+
// Arrange
148+
var mock = new HttpMock();
149+
var key = $"{Guid.NewGuid()}|{Guid.NewGuid()}";
150+
151+
mock.ForDelete()
152+
.WithPath($"IncomeRelations/{key}")
153+
.RespondsWithStatus(HttpStatusCode.OK);
154+
155+
// Act
156+
var client = mock.GetClient();
157+
var response = await client.DeleteAsync($"https://localhost/IncomeRelations/{key}");
158+
159+
// Assert
160+
response.StatusCode.Should().Be(HttpStatusCode.OK);
161+
}
162+
163+
[Fact]
164+
public async Task Can_match_query_with_pipe_character()
165+
{
166+
// Arrange
167+
var mock = new HttpMock();
168+
var filter = "status=active|pending";
169+
170+
mock.ForGet()
171+
.WithPath("api/items")
172+
.WithQuery($"filter={filter}")
173+
.RespondsWithStatus(HttpStatusCode.OK);
174+
175+
// Act
176+
var client = mock.GetClient();
177+
var response = await client.GetAsync($"https://localhost/api/items?filter={filter}");
178+
179+
// Assert
180+
response.StatusCode.Should().Be(HttpStatusCode.OK);
181+
}
182+
144183
[Fact]
145184
public async Task Can_mock_get_request_with_json_response()
146185
{

Mockly/RequestMock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public async Task<bool> Matches(RequestInfo request)
8585
// Check path pattern if specified
8686
if (PathPattern != null)
8787
{
88-
var path = request.Uri?.AbsolutePath ?? string.Empty;
88+
var path = WebUtility.UrlDecode(request.Uri?.AbsolutePath ?? string.Empty);
8989
if (!MatchesPattern(path.TrimStart('/'), PathPattern.TrimStart('/')))
9090
{
9191
return false;

0 commit comments

Comments
 (0)