Skip to content

Commit b740db3

Browse files
authored
Allows undefined values to pass from mongo to database controler (#4973)
* Allows undefined values to pass from mongo to database controler * Adds changelog
1 parent 942b9b5 commit b740db3

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Adds Pipeline Operator to Aggregate Router
88

99
#### Bug Fixes:
10+
* Fixes issue that would crash the server when mongo objects had undefined values [#4966](https://github.com/parse-community/parse-server/issues/4966)
1011
* Fixes issue that prevented ACL's from being used with `select` (see [#571](https://github.com/parse-community/Parse-SDK-JS/issues/571))
1112

1213
#### Dependency updates:

spec/MongoTransform.spec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,32 @@ describe('parseObjectToMongoObjectForCreate', () => {
354354
done();
355355
});
356356

357+
it('object with undefined nested values', () => {
358+
const input = {
359+
_id: 'vQHyinCW1l',
360+
urls: { firstUrl: 'https://', secondUrl: undefined }, };
361+
const output = transform.mongoObjectToParseObject(null, input, {
362+
fields: {
363+
urls: { type: 'Object' }
364+
}
365+
});
366+
expect(output.urls).toEqual({
367+
firstUrl: 'https://', secondUrl: undefined
368+
});
369+
});
370+
371+
it('undefined objects', () => {
372+
const input = {
373+
_id: 'vQHyinCW1l',
374+
urls: undefined, };
375+
const output = transform.mongoObjectToParseObject(null, input, {
376+
fields: {
377+
urls: { type: 'Object' }
378+
}
379+
});
380+
expect(output.urls).toBeUndefined();
381+
});
382+
357383
it('$regex in $all list', (done) => {
358384
const input = {
359385
arrayField: {'$all': [{$regex: '^\\Qone\\E'}, {$regex: '^\\Qtwo\\E'}, {$regex: '^\\Qthree\\E'}]},

src/Adapters/Storage/Mongo/MongoTransform.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,11 +1078,11 @@ const nestedMongoObjectToNestedParseObject = mongoObject => {
10781078
case 'string':
10791079
case 'number':
10801080
case 'boolean':
1081-
return mongoObject;
10821081
case 'undefined':
1082+
return mongoObject;
10831083
case 'symbol':
10841084
case 'function':
1085-
throw 'bad value in mongoObjectToParseObject';
1085+
throw 'bad value in nestedMongoObjectToNestedParseObject';
10861086
case 'object':
10871087
if (mongoObject === null) {
10881088
return null;
@@ -1137,8 +1137,8 @@ const mongoObjectToParseObject = (className, mongoObject, schema) => {
11371137
case 'string':
11381138
case 'number':
11391139
case 'boolean':
1140-
return mongoObject;
11411140
case 'undefined':
1141+
return mongoObject;
11421142
case 'symbol':
11431143
case 'function':
11441144
throw 'bad value in mongoObjectToParseObject';

0 commit comments

Comments
 (0)