diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000..a15ba0c2fa Binary files /dev/null and b/.DS_Store differ diff --git a/spec/ParseObject.spec.js b/spec/ParseObject.spec.js index 5d8996559b..10a44e9f6d 100644 --- a/spec/ParseObject.spec.js +++ b/spec/ParseObject.spec.js @@ -335,6 +335,11 @@ describe('Parse.Object testing', () => { 'Item should not be updated with invalid key.'); item.save({ "foo^bar": "baz" }).then(fail, done); }); + + it("invalid __type", function(done) { + var item = new Parse.Object("Item"); + item.save({ "foo": {__type: "IvalidName"} }).then(fail, done); + }); it("simple field deletion", function(done) { var simple = new Parse.Object("SimpleObject"); diff --git a/src/Schema.js b/src/Schema.js index a202c7e36f..e6ec375498 100644 --- a/src/Schema.js +++ b/src/Schema.js @@ -620,7 +620,7 @@ Schema.prototype.validateRequiredColumns = function(className, object, query) { if (!columns || columns.length == 0) { return Promise.resolve(this); } - + var missingColumns = columns.filter(function(column){ if (query && query.objectId) { if (object[column] && typeof object[column] === "object") { @@ -630,15 +630,15 @@ Schema.prototype.validateRequiredColumns = function(className, object, query) { // Not trying to do anything there return false; } - return !object[column] + return !object[column] }); - + if (missingColumns.length > 0) { throw new Parse.Error( Parse.Error.INCORRECT_TYPE, missingColumns[0]+' is required.'); } - + return Promise.resolve(this); } @@ -725,19 +725,45 @@ function getObjectType(obj) { if (obj instanceof Array) { return 'array'; } - if (obj.__type === 'Pointer' && obj.className) { - return '*' + obj.className; - } - if (obj.__type === 'File' && obj.name) { - return 'file'; - } - if (obj.__type === 'Date' && obj.iso) { - return 'date'; - } - if (obj.__type == 'GeoPoint' && - obj.latitude != null && - obj.longitude != null) { - return 'geopoint'; + if (obj.__type){ + switch(obj.__type) { + case 'Pointer' : + if(obj.className) { + return '*' + obj.className; + } else { + throw new Parse.Error(Parse.Error.INVALID_POINTER, JSON.stringify(obj) + " is not a valid Pointer"); + } + break; + case 'File' : + if(obj.name) { + return 'file'; + } else { + let msg = obj.name? JSON.stringify(obj) + " is not a valid File" : "File has no name"; + throw new Parse.Error(Parse.Error.INCORRECT_TYPE, msg); + } + break; + case 'Date' : + if(obj.iso) { + return 'date'; + } else { + throw new Parse.Error(Parse.Error.INCORRECT_TYPE, JSON.stringify(obj) + " is not a valid Date"); + } + break; + case 'GeoPoint' : + if(obj.latitude != null && obj.longitude != null) { + return 'geopoint'; + } else { + throw new Parse.Error(Parse.Error.INCORRECT_TYPE, JSON.stringify(obj) + " is not a valid GeoPoint"); + } + break; + case 'Bytes' : + if(!obj.base64) { + throw new Parse.Error(Parse.Error.INCORRECT_TYPE, 'Bytes type has no base64 field: ' + JSON.stringify(obj)); + } + break; + default : + throw new Parse.Error(Parse.Error.INCORRECT_TYPE, 'invalid type: ' + obj.__type); + } } if (obj['$ne']) { return getObjectType(obj['$ne']);