Skip to content

Commit a99d08d

Browse files
authored
Merge pull request #15098 from Automattic/vkarpov15/gh-15071
fix(document+schema): add potential fix for #15071
2 parents d2a70e3 + 7b0dba0 commit a99d08d

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/document.js

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

17781778
Document.prototype.$__getValue = function(path) {
1779+
if (typeof path !== 'string' && !Array.isArray(path)) {
1780+
throw new TypeError(
1781+
`Invalid \`path\`. Must be either string or array. Got "${path}" (type ${typeof path})`
1782+
);
1783+
}
17791784
return utils.getValue(path, this._doc);
17801785
};
17811786

lib/schema.js

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

12441244
for (const path of Object.keys(this.paths)) {
1245+
if (typeof path !== 'string') {
1246+
continue;
1247+
}
12451248
const schematype = this.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)