Skip to content
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

Fix JsonPartialMatcher when using property names with dot #1216

Merged
merged 3 commits into from
Dec 6, 2024
Merged
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
2 changes: 1 addition & 1 deletion src/WireMock.Net/Matchers/AbstractJsonPartialMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected override bool IsMatch(JToken value, JToken? input)
case JTokenType.Object:
var nestedValues = value.ToObject<Dictionary<string, JToken>>();
return nestedValues?.Any() != true ||
nestedValues.All(pair => IsMatch(pair.Value, input.SelectToken(pair.Key)));
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.

case JTokenType.Array:
var valuesArray = value.ToObject<JToken[]>();
Expand Down
17 changes: 17 additions & 0 deletions test/WireMock.Net.Tests/Matchers/JsonPartialMatcherTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,23 @@ public void JsonPartialMatcher_IsMatch_JObjectAsString()
Assert.Equal(1.0, match);
}

[Fact]
public void JsonPartialMatcher_IsMatch_JObjectAsStringWithDottedPropertyName()
{
// Assign
var matcher = new JsonPartialMatcher("{ \"urn:ietf:params:scim:schemas:extension:enterprise:2.0:User\" : \"Test\" }");

// Act
var jObject = new JObject
{
{ "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User", new JValue("Test") }
};
var match = matcher.IsMatch(jObject).Score;

// Assert
Assert.Equal(1.0, match);
}

[Fact]
public void JsonPartialMatcher_IsMatch_GuidAsString()
{
Expand Down
Loading