Skip to content

Commit e182fe5

Browse files
authored
Merge pull request #14198 from Automattic/vkarpov15/gh-14178
fix(document): avoid flattening dotted paths in mixed path underneath nested path
2 parents 44f391b + dabb2cf commit e182fe5

File tree

3 files changed

+23
-42
lines changed

3 files changed

+23
-42
lines changed

lib/document.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const cleanModifiedSubpaths = require('./helpers/document/cleanModifiedSubpaths'
2222
const compile = require('./helpers/document/compile').compile;
2323
const defineKey = require('./helpers/document/compile').defineKey;
2424
const flatten = require('./helpers/common').flatten;
25-
const flattenObjectWithDottedPaths = require('./helpers/path/flattenObjectWithDottedPaths');
2625
const get = require('./helpers/get');
2726
const getEmbeddedDiscriminatorPath = require('./helpers/document/getEmbeddedDiscriminatorPath');
2827
const getKeysInSchemaOrder = require('./helpers/schema/getKeysInSchemaOrder');
@@ -472,8 +471,6 @@ function $applyDefaultsToNested(val, path, doc) {
472471
return;
473472
}
474473

475-
flattenObjectWithDottedPaths(val);
476-
477474
const paths = Object.keys(doc.$__schema.paths);
478475
const plen = paths.length;
479476

lib/helpers/path/flattenObjectWithDottedPaths.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

test/document.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12414,6 +12414,29 @@ describe('document', function() {
1241412414
await doc.save();
1241512415
assert.ok(doc);
1241612416
});
12417+
12418+
it('avoids overwriting dotted paths in mixed path underneath nested path (gh-14178)', async function() {
12419+
const testSchema = new Schema({
12420+
__stateBeforeSuspension: {
12421+
field1: String,
12422+
field3: { type: Schema.Types.Mixed }
12423+
}
12424+
});
12425+
const Test = db.model('Test', testSchema);
12426+
const eventObj = new Test({
12427+
__stateBeforeSuspension: { field1: 'test' }
12428+
});
12429+
await eventObj.save();
12430+
const newO = eventObj.toObject();
12431+
newO.__stateBeforeSuspension.field3 = { '.ippo': 5 };
12432+
eventObj.set(newO);
12433+
await eventObj.save();
12434+
12435+
assert.strictEqual(eventObj.__stateBeforeSuspension.field3['.ippo'], 5);
12436+
12437+
const fromDb = await Test.findById(eventObj._id).lean().orFail();
12438+
assert.strictEqual(fromDb.__stateBeforeSuspension.field3['.ippo'], 5);
12439+
});
1241712440
});
1241812441

1241912442
describe('Check if instance function that is supplied in schema option is availabe', function() {

0 commit comments

Comments
 (0)