We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6e782da commit b526145Copy full SHA for b526145
lib/bson/objectid.js
@@ -66,7 +66,7 @@ var ObjectID = function ObjectID(id) {
66
} else if (id != null && id.length === 12) {
67
// assume 12 byte string
68
this.id = id;
69
- } else if (id != null && id.toHexString) {
+ } else if (id != null && typeof id.toHexString === 'function') {
70
// Duck-typing to support ObjectId from different npm packages
71
return id;
72
} else {
@@ -357,7 +357,10 @@ ObjectID.isValid = function isValid(id) {
357
}
358
359
// Duck-Typing detection of ObjectId like objects
360
- if (id.toHexString) {
+ if (
361
+ typeof id.toHexString === 'function' &&
362
+ (id.id instanceof _Buffer || typeof id.id === 'string')
363
+ ) {
364
return id.id.length === 12 || (id.id.length === 24 && checkForHexRegExp.test(id.id));
365
366
0 commit comments