add invalid __type check

This commit is contained in:
jim1_lin
2016-02-26 16:39:27 +08:00
committed by Jim Lin
parent bd89338b39
commit d067c0ba61
2 changed files with 34 additions and 17 deletions

View File

@@ -336,6 +336,11 @@ describe('Parse.Object testing', () => {
item.save({ "foo^bar": "baz" }).then(fail, done); 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) { it("simple field deletion", function(done) {
var simple = new Parse.Object("SimpleObject"); var simple = new Parse.Object("SimpleObject");
simple.save({ simple.save({

View File

@@ -731,20 +731,32 @@ function getObjectType(obj) {
if (obj instanceof Array) { if (obj instanceof Array) {
return 'array'; return 'array';
} }
if (obj.__type === 'Pointer' && obj.className) { if (obj.__type){
switch(obj.__type) {
case 'Pointer' :
if(obj.className) {
return '*' + obj.className; return '*' + obj.className;
} }
if (obj.__type === 'File' && obj.name) { break;
case 'File' :
if(obj.url && obj.name) {
return 'file'; return 'file';
} }
if (obj.__type === 'Date' && obj.iso) { break;
case 'Date' :
if(obj.iso) {
return 'date'; return 'date';
} }
if (obj.__type == 'GeoPoint' && break;
obj.latitude != null && case 'GeoPoint' :
obj.longitude != null) { if(obj.latitude != null && obj.longitude != null) {
return 'geopoint'; return 'geopoint';
} }
break;
default :
throw new Parse.Error(Parse.Error.INCORRECT_TYPE, 'invalid type: ' + obj.__type);
}
}
if (obj['$ne']) { if (obj['$ne']) {
return getObjectType(obj['$ne']); return getObjectType(obj['$ne']);
} }