Skip to content

Commit 11301d9

Browse files
yuzehdrew-gross
authored andcommitted
Fix an issue in MongoTransform where transforming object type fields with null values fails (#2029)
1 parent a00d795 commit 11301d9

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

spec/MongoTransform.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ describe('parseObjectToMongoObjectForCreate', () => {
1616
done();
1717
});
1818

19+
it('an object with null values', (done) => {
20+
var input = {objectWithNullValues: {isNull: null, notNull: 3}};
21+
var output = transform.parseObjectToMongoObjectForCreate(null, input, {
22+
fields: {objectWithNullValues: {type: 'object'}}
23+
});
24+
jequal(input, output);
25+
done();
26+
});
27+
1928
it('built-in timestamps', (done) => {
2029
var input = {
2130
createdAt: "2015-10-06T21:24:50.332Z",

spec/helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ function arrayContains(arr, item) {
209209

210210
// Normalizes a JSON object.
211211
function normalize(obj) {
212-
if (typeof obj !== 'object') {
212+
if (obj === null || typeof obj !== 'object') {
213213
return JSON.stringify(obj);
214214
}
215215
if (obj instanceof Array) {

src/Adapters/Storage/Mongo/MongoTransform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const transformKeyValueForUpdate = (className, restKey, restValue, parseFormatSc
8383
}
8484

8585
const transformInteriorValue = restValue => {
86-
if (typeof restValue === 'object' && Object.keys(restValue).some(key => key.includes('$') || key.includes('.'))) {
86+
if (restValue !== null && typeof restValue === 'object' && Object.keys(restValue).some(key => key.includes('$') || key.includes('.'))) {
8787
throw new Parse.Error(Parse.Error.INVALID_NESTED_KEY, "Nested keys should not contain the '$' or '.' characters");
8888
}
8989
// Handle atomic values

0 commit comments

Comments
 (0)