Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12719 from zzztttkkk/master
make `modifiedPaths` safer.
- Loading branch information
Showing
2 changed files
with
51 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const start = require('../common'); | ||
|
||
const modifiedPaths = require('../../lib/helpers/common').modifiedPaths; | ||
const mongoose = start.mongoose; | ||
const { Schema } = mongoose; | ||
|
||
|
||
describe('modifiedPaths, bad update value which has circular reference field', () => { | ||
it('update value can be null', function() { | ||
modifiedPaths(null, 'path', null); | ||
}); | ||
|
||
it('values with obvious error on circular reference', function() { | ||
const objA = {}; | ||
objA.a = objA; | ||
|
||
assert.throws(() => modifiedPaths(objA, 'path', null), /circular reference/); | ||
}); | ||
}); |