Skip to content

Fix problems with _keys in nested objects #532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions spec/ParseObject.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
})
})
});
8 changes: 3 additions & 5 deletions src/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ function transformUpdateOperator(operator, flatten) {

// Converts from a mongo-format object to a REST-format object.
// 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) {
case 'string':
case 'number':
Expand Down Expand Up @@ -683,10 +683,8 @@ function untransformObject(schema, className, mongoObject) {
objectId: objData[1]
};
break;
} else if (key[0] == '_' && key != '__type') {
} else if (!isNestedObject && key[0] == '_' && key != '__type') {
throw ('bad key in untransform: ' + key);
//} else if (mongoObject[key] === null) {
//break;
} else {
var expectedType = schema.getExpectedType(className, key);
var value = mongoObject[key];
Expand All @@ -700,7 +698,7 @@ function untransformObject(schema, className, mongoObject) {
}
}
restObject[key] = untransformObject(schema, className,
mongoObject[key]);
mongoObject[key], true);
}
}
return restObject;
Expand Down