Fix an issue in MongoTransform where transforming object type fields with null values fails (#2029)
This commit is contained in:
@@ -16,6 +16,15 @@ describe('parseObjectToMongoObjectForCreate', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('an object with null values', (done) => {
|
||||||
|
var input = {objectWithNullValues: {isNull: null, notNull: 3}};
|
||||||
|
var output = transform.parseObjectToMongoObjectForCreate(null, input, {
|
||||||
|
fields: {objectWithNullValues: {type: 'object'}}
|
||||||
|
});
|
||||||
|
jequal(input, output);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
it('built-in timestamps', (done) => {
|
it('built-in timestamps', (done) => {
|
||||||
var input = {
|
var input = {
|
||||||
createdAt: "2015-10-06T21:24:50.332Z",
|
createdAt: "2015-10-06T21:24:50.332Z",
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ function arrayContains(arr, item) {
|
|||||||
|
|
||||||
// Normalizes a JSON object.
|
// Normalizes a JSON object.
|
||||||
function normalize(obj) {
|
function normalize(obj) {
|
||||||
if (typeof obj !== 'object') {
|
if (obj === null || typeof obj !== 'object') {
|
||||||
return JSON.stringify(obj);
|
return JSON.stringify(obj);
|
||||||
}
|
}
|
||||||
if (obj instanceof Array) {
|
if (obj instanceof Array) {
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ const transformKeyValueForUpdate = (className, restKey, restValue, parseFormatSc
|
|||||||
}
|
}
|
||||||
|
|
||||||
const transformInteriorValue = restValue => {
|
const transformInteriorValue = restValue => {
|
||||||
if (typeof restValue === 'object' && Object.keys(restValue).some(key => key.includes('$') || key.includes('.'))) {
|
if (restValue !== null && typeof restValue === 'object' && Object.keys(restValue).some(key => key.includes('$') || key.includes('.'))) {
|
||||||
throw new Parse.Error(Parse.Error.INVALID_NESTED_KEY, "Nested keys should not contain the '$' or '.' characters");
|
throw new Parse.Error(Parse.Error.INVALID_NESTED_KEY, "Nested keys should not contain the '$' or '.' characters");
|
||||||
}
|
}
|
||||||
// Handle atomic values
|
// Handle atomic values
|
||||||
|
|||||||
Reference in New Issue
Block a user