Skip to content

Commit 35e9e6e

Browse files
committed
fix(document): copy date objects correctly when strict = false
Fix #7907
1 parent 41ad80a commit 35e9e6e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/document.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ Document.prototype.$set = function $set(path, val, type, options) {
844844
}
845845

846846
if (typeof path[key] === 'object' &&
847-
!Array.isArray(path[key]) &&
847+
!utils.isNativeObject(path[key]) &&
848848
path[key] != null &&
849849
pathtype !== 'virtual' &&
850850
pathtype !== 'real' &&

lib/utils.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,19 @@ exports.isPOJO = function isPOJO(arg) {
494494
return !proto || proto.constructor.name === 'Object';
495495
};
496496

497+
/*!
498+
* Determines if `obj` is a built-in object like an array, date, boolean,
499+
* etc.
500+
*/
501+
502+
exports.isNativeObject = function(arg) {
503+
return Array.isArray(arg) ||
504+
arg instanceof Date ||
505+
arg instanceof Boolean ||
506+
arg instanceof Number ||
507+
arg instanceof String;
508+
};
509+
497510
/*!
498511
* Search if `obj` or any POJOs nested underneath `obj` has a property named
499512
* `key`

0 commit comments

Comments
 (0)