Skip to content

Commit 99fb598

Browse files
committed
fix(document+schema): add potential fix for Automattic#15071
1 parent 7ed441e commit 99fb598

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/document.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,6 +1777,15 @@ Document.prototype.$__set = function(pathToMark, path, options, constructing, pa
17771777
*/
17781778

17791779
Document.prototype.$__getValue = function(path) {
1780+
if (typeof path !== 'string' && !Array.isArray(path)) {
1781+
throw new TypeError(
1782+
'Invalid `path`. Must be either string or array. Got "' +
1783+
path +
1784+
'" (type ' +
1785+
typeof path +
1786+
')'
1787+
);
1788+
}
17801789
return utils.getValue(path, this._doc);
17811790
};
17821791

lib/schema.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,11 +1242,22 @@ function gatherChildSchemas(schema) {
12421242
const childSchemas = [];
12431243

12441244
for (const path of Object.keys(schema.paths)) {
1245+
if (typeof path !== 'string') {
1246+
continue;
1247+
}
12451248
const schematype = schema.paths[path];
12461249
if (schematype.$isMongooseDocumentArray || schematype.$isSingleNested) {
1247-
childSchemas.push({ schema: schematype.schema, model: schematype.caster, path: path });
1250+
childSchemas.push({
1251+
schema: schematype.schema,
1252+
model: schematype.caster,
1253+
path: path
1254+
});
12481255
} else if (schematype.$isSchemaMap && schematype.$__schemaType.$isSingleNested) {
1249-
childSchemas.push({ schema: schematype.$__schemaType.schema, model: schematype.$__schemaType.caster, path: path });
1256+
childSchemas.push({
1257+
schema: schematype.$__schemaType.schema,
1258+
model: schematype.$__schemaType.caster,
1259+
path: path
1260+
});
12501261
}
12511262
}
12521263

0 commit comments

Comments
 (0)