Skip to content
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

fix: Nested date is incorrectly decoded as empty object {} when fetching a Parse Object #8446

Merged
merged 3 commits into from
Mar 5, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions spec/MongoStorageAdapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ describe_only_db('mongo')('MongoStorageAdapter', () => {
expect(object.date[0] instanceof Date).toBeTrue();
expect(object.bar.date[0] instanceof Date).toBeTrue();
expect(object.foo.test.date[0] instanceof Date).toBeTrue();
const obj = await new Parse.Query('MyClass').first({useMasterKey: true});
expect(obj.get('date')[0] instanceof Date).toBeTrue();
expect(obj.get('bar').date[0] instanceof Date).toBeTrue();
expect(obj.get('foo').test.date[0] instanceof Date).toBeTrue();
});

it('handles updating a single object with array, object date', done => {
Expand Down
13 changes: 10 additions & 3 deletions src/Adapters/Storage/Mongo/MongoTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@ const transformInteriorValue = restValue => {
// Handle atomic values
var value = transformInteriorAtom(restValue);
if (value !== CannotTransform) {
if (value && typeof value === 'object') {
if (value instanceof Date) {
return value;
}
if (value instanceof Array) {
value = value.map(transformInteriorValue);
} else {
value = mapValues(value, transformInteriorValue);
}
}
return value;
}

Expand Down Expand Up @@ -1014,9 +1024,6 @@ function mapValues(object, iterator) {
const result = {};
Object.keys(object).forEach(key => {
result[key] = iterator(object[key]);
if (result[key] && JSON.stringify(result[key]).includes(`"__type"`)) {
result[key] = mapValues(object[key], iterator);
}
});
return result;
}
Expand Down