Skip to content

Commit a739668

Browse files
committed
RegexMatcher also checks request path
1 parent ee2dbb5 commit a739668

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

UnitTests/TestRegExMatcher.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Threading.Tasks;
55
using Xunit;
66
using netmockery;
7-
7+
using Microsoft.AspNetCore.Http;
88

99
namespace UnitTests
1010
{
@@ -37,5 +37,13 @@ public void NoMatch()
3737
Assert.False(matcher.Matches(null, BODY, null));
3838
}
3939

40+
[Fact]
41+
public void MatchesBothUrlAndBody()
42+
{
43+
var matcher = new RegexMatcher("abcde");
44+
Assert.True(matcher.Matches(new PathString("/foo/bar/ae/fx/"), "content in body: abcde", null));
45+
Assert.True(matcher.Matches(new PathString("/foo/bar/abcde/fx/"), "", null));
46+
}
47+
4048
}
4149
}

netmockery/RequestMatcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public RegexMatcher(string regex)
4545

4646
public override bool Matches(PathString path, string body, IHeaderDictionary headers)
4747
{
48-
return Regex.IsMatch(body, _regex);
48+
return Regex.IsMatch(path.ToString(), _regex) || Regex.IsMatch(body, _regex);
4949
}
5050

5151
public override string ToString()

0 commit comments

Comments
 (0)