diff --git a/CHANGELOG.md b/CHANGELOG.md index 36318bfd..0b29812c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Adds Pipeline Operator to Aggregate Router #### Bug Fixes: +* Fixes issue that would crash the server when mongo objects had undefined values [#4966](https://github.com/parse-community/parse-server/issues/4966) * Fixes issue that prevented ACL's from being used with `select` (see [#571](https://github.com/parse-community/Parse-SDK-JS/issues/571)) #### Dependency updates: diff --git a/spec/MongoTransform.spec.js b/spec/MongoTransform.spec.js index c38346c1..24d1eb96 100644 --- a/spec/MongoTransform.spec.js +++ b/spec/MongoTransform.spec.js @@ -354,6 +354,32 @@ describe('parseObjectToMongoObjectForCreate', () => { done(); }); + it('object with undefined nested values', () => { + const input = { + _id: 'vQHyinCW1l', + urls: { firstUrl: 'https://', secondUrl: undefined }, }; + const output = transform.mongoObjectToParseObject(null, input, { + fields: { + urls: { type: 'Object' } + } + }); + expect(output.urls).toEqual({ + firstUrl: 'https://', secondUrl: undefined + }); + }); + + it('undefined objects', () => { + const input = { + _id: 'vQHyinCW1l', + urls: undefined, }; + const output = transform.mongoObjectToParseObject(null, input, { + fields: { + urls: { type: 'Object' } + } + }); + expect(output.urls).toBeUndefined(); + }); + it('$regex in $all list', (done) => { const input = { arrayField: {'$all': [{$regex: '^\\Qone\\E'}, {$regex: '^\\Qtwo\\E'}, {$regex: '^\\Qthree\\E'}]}, diff --git a/src/Adapters/Storage/Mongo/MongoTransform.js b/src/Adapters/Storage/Mongo/MongoTransform.js index 453bddef..ebd980a6 100644 --- a/src/Adapters/Storage/Mongo/MongoTransform.js +++ b/src/Adapters/Storage/Mongo/MongoTransform.js @@ -1078,11 +1078,11 @@ const nestedMongoObjectToNestedParseObject = mongoObject => { case 'string': case 'number': case 'boolean': - return mongoObject; case 'undefined': + return mongoObject; case 'symbol': case 'function': - throw 'bad value in mongoObjectToParseObject'; + throw 'bad value in nestedMongoObjectToNestedParseObject'; case 'object': if (mongoObject === null) { return null; @@ -1137,8 +1137,8 @@ const mongoObjectToParseObject = (className, mongoObject, schema) => { case 'string': case 'number': case 'boolean': - return mongoObject; case 'undefined': + return mongoObject; case 'symbol': case 'function': throw 'bad value in mongoObjectToParseObject';