Fix problems with _keys in nested objects
This commit is contained in:
@@ -1736,4 +1736,33 @@ describe('Parse.Object testing', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it("should create nested keys with _", done => {
|
||||||
|
const object = new Parse.Object("AnObject");
|
||||||
|
object.set("foo", {
|
||||||
|
"_bar": "_",
|
||||||
|
"baz_bar": 1,
|
||||||
|
"__foo_bar": true,
|
||||||
|
"_0": "underscore_zero",
|
||||||
|
"_more": {
|
||||||
|
"_nested": "key"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
object.save().then( res => {
|
||||||
|
ok(res);
|
||||||
|
return res.fetch();
|
||||||
|
}).then( res => {
|
||||||
|
const foo = res.get("foo");
|
||||||
|
expect(foo["_bar"]).toEqual("_");
|
||||||
|
expect(foo["baz_bar"]).toEqual(1);
|
||||||
|
expect(foo["__foo_bar"]).toBe(true);
|
||||||
|
expect(foo["_0"]).toEqual("underscore_zero");
|
||||||
|
expect(foo["_more"]["_nested"]).toEqual("key");
|
||||||
|
done();
|
||||||
|
}).fail( err => {
|
||||||
|
console.error(err);
|
||||||
|
fail("should not fail");
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -586,7 +586,7 @@ function transformUpdateOperator(operator, flatten) {
|
|||||||
|
|
||||||
// Converts from a mongo-format object to a REST-format object.
|
// Converts from a mongo-format object to a REST-format object.
|
||||||
// Does not strip out anything based on a lack of authentication.
|
// Does not strip out anything based on a lack of authentication.
|
||||||
function untransformObject(schema, className, mongoObject) {
|
function untransformObject(schema, className, mongoObject, isNestedObject = false) {
|
||||||
switch(typeof mongoObject) {
|
switch(typeof mongoObject) {
|
||||||
case 'string':
|
case 'string':
|
||||||
case 'number':
|
case 'number':
|
||||||
@@ -683,10 +683,8 @@ function untransformObject(schema, className, mongoObject) {
|
|||||||
objectId: objData[1]
|
objectId: objData[1]
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
} else if (key[0] == '_' && key != '__type') {
|
} else if (!isNestedObject && key[0] == '_' && key != '__type') {
|
||||||
throw ('bad key in untransform: ' + key);
|
throw ('bad key in untransform: ' + key);
|
||||||
//} else if (mongoObject[key] === null) {
|
|
||||||
//break;
|
|
||||||
} else {
|
} else {
|
||||||
var expectedType = schema.getExpectedType(className, key);
|
var expectedType = schema.getExpectedType(className, key);
|
||||||
var value = mongoObject[key];
|
var value = mongoObject[key];
|
||||||
@@ -700,7 +698,7 @@ function untransformObject(schema, className, mongoObject) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
restObject[key] = untransformObject(schema, className,
|
restObject[key] = untransformObject(schema, className,
|
||||||
mongoObject[key]);
|
mongoObject[key], true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return restObject;
|
return restObject;
|
||||||
|
|||||||
Reference in New Issue
Block a user