Skip to content

Commit 7f640df

Browse files
authored
Fix JsonPartialMatcher when using property names with dot (#1216)
Fix JsonPartialMatcher when using property names with dot (#1216)
1 parent 4b3e9fe commit 7f640df

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/WireMock.Net/Matchers/AbstractJsonPartialMatcher.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ protected override bool IsMatch(JToken value, JToken? input)
8282
case JTokenType.Object:
8383
var nestedValues = value.ToObject<Dictionary<string, JToken>>();
8484
return nestedValues?.Any() != true ||
85-
nestedValues.All(pair => IsMatch(pair.Value, input.SelectToken(pair.Key)));
85+
nestedValues.All(pair => IsMatch(pair.Value, input.SelectToken(pair.Key) ?? input[pair.Key])); // First try to select based on JPath expression, else just get the value.
8686

8787
case JTokenType.Array:
8888
var valuesArray = value.ToObject<JToken[]>();

test/WireMock.Net.Tests/Matchers/JsonPartialMatcherTests.cs

+17
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,23 @@ public void JsonPartialMatcher_IsMatch_JObjectAsString()
293293
Assert.Equal(1.0, match);
294294
}
295295

296+
[Fact]
297+
public void JsonPartialMatcher_IsMatch_JObjectAsStringWithDottedPropertyName()
298+
{
299+
// Assign
300+
var matcher = new JsonPartialMatcher("{ \"urn:ietf:params:scim:schemas:extension:enterprise:2.0:User\" : \"Test\" }");
301+
302+
// Act
303+
var jObject = new JObject
304+
{
305+
{ "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User", new JValue("Test") }
306+
};
307+
var match = matcher.IsMatch(jObject).Score;
308+
309+
// Assert
310+
Assert.Equal(1.0, match);
311+
}
312+
296313
[Fact]
297314
public void JsonPartialMatcher_IsMatch_GuidAsString()
298315
{

0 commit comments

Comments
 (0)