Fixes an issue with matching JSON bodies as bytes (#1339)

* Fixes an issue with matching JSON bodies as bytes

* Adding tests for exact object matching

* Simplify the check for byte data
This commit is contained in:
Sam Fields
2025-08-02 14:11:13 -04:00
committed by GitHub
parent e400e92452
commit 6ccfe68686
2 changed files with 79 additions and 10 deletions

View File

@@ -34,14 +34,10 @@ internal static class BodyDataMatchScoreCalculator
}
}
if (matcher is ExactObjectMatcher exactObjectMatcher)
if (matcher is ExactObjectMatcher { Value: byte[] } exactObjectMatcher)
{
// If the body is a byte array, try to match.
var detectedBodyType = requestMessage.DetectedBodyType;
if (detectedBodyType is BodyType.Bytes or BodyType.String or BodyType.FormUrlEncoded)
{
return exactObjectMatcher.IsMatch(requestMessage.BodyAsBytes);
}
return exactObjectMatcher.IsMatch(requestMessage.BodyAsBytes);
}
// Check if the matcher is a IObjectMatcher
@@ -74,4 +70,4 @@ internal static class BodyDataMatchScoreCalculator
return default;
}
}
}