Skip to content

Commit

Permalink
fix: avoid copying Object.prototype properties when cloning
Browse files Browse the repository at this point in the history
Fix #9876
  • Loading branch information
vkarpov15 committed Feb 12, 2021
1 parent 425f35a commit 7c41ddc
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/helpers/clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function cloneObject(obj, options, isArrayChild) {
const ret = {};
let hasKeys;

for (const k in obj) {
for (const k of Object.keys(obj)) {
if (specialProperties.has(k)) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/query/castFilterPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = function castFilterPath(query, schematype, val) {
if (nested && schematype && !schematype.caster) {
const _keys = Object.keys(nested);
if (_keys.length && isOperator(_keys[0])) {
for (const key in nested) {
for (const key of Object.keys(nested)) {
nested[key] = schematype.castForQueryWrapper({
$conditional: key,
val: nested[key],
Expand Down
3 changes: 1 addition & 2 deletions lib/helpers/update/castArrayFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ module.exports = function castArrayFilters(query) {
if (filter == null) {
throw new Error(`Got null array filter in ${arrayFilters}`);
}
for (const key in filter) {

for (const key of Object.keys(filter)) {
if (filter[key] == null) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -4966,7 +4966,7 @@ Query.prototype.tailable = function(val, opts) {
}

if (opts && typeof opts === 'object') {
for (const key in opts) {
for (const key of Object.keys(opts)) {
if (key === 'awaitdata') {
// For backwards compatibility
this.options[key] = !!opts[key];
Expand Down
10 changes: 5 additions & 5 deletions lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,18 +694,18 @@ Schema.prototype.path = function(path, obj) {
}

if (schemaType.$isSingleNested) {
for (const key in schemaType.schema.paths) {
for (const key of Object.keys(schemaType.schema.paths)) {
this.singleNestedPaths[path + '.' + key] = schemaType.schema.paths[key];
}
for (const key in schemaType.schema.singleNestedPaths) {
for (const key of Object.keys(schemaType.schema.singleNestedPaths)) {
this.singleNestedPaths[path + '.' + key] =
schemaType.schema.singleNestedPaths[key];
}
for (const key in schemaType.schema.subpaths) {
for (const key of Object.keys(schemaType.schema.subpaths)) {
this.singleNestedPaths[path + '.' + key] =
schemaType.schema.subpaths[key];
}
for (const key in schemaType.schema.nested) {
for (const key of Object.keys(schemaType.schema.nested)) {
this.singleNestedPaths[path + '.' + key] = 'nested';
}

Expand Down Expand Up @@ -1156,7 +1156,7 @@ Schema.prototype.hasMixedParent = function(path) {
path = '';
for (let i = 0; i < subpaths.length; ++i) {
path = i > 0 ? path + '.' + subpaths[i] : subpaths[i];
if (path in this.paths &&
if (this.paths.hasOwnProperty(path) &&
this.paths[path] instanceof MongooseTypes.Mixed) {
return this.paths[path];
}
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ exports.toObject = function toObject(obj) {
if (exports.isPOJO(obj)) {
ret = {};

for (const k in obj) {
for (const k of Object.keys(obj)) {
if (specialProperties.has(k)) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"mongodb": "3.6.4",
"mongoose-legacy-pluralize": "1.0.2",
"mpath": "0.8.3",
"mquery": "3.2.3",
"mquery": "3.2.4",
"ms": "2.1.2",
"regexp-clone": "1.0.0",
"safe-buffer": "5.2.1",
Expand Down

0 comments on commit 7c41ddc

Please sign in to comment.