Skip to content

Commit f9148ab

Browse files
committed
fix: narrow toJSONwithObjects to only serialize Parse.ACL, preserving Date instances
Calling val.toJSON() on all objects with a toJSON method converts Date instances to ISO strings, breaking directAccess consumers. Narrowing to Parse.ACL fixes the original bug without regressing Date fields.
1 parent 03a62e1 commit f9148ab

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

spec/CloudCode.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3659,13 +3659,19 @@ describe('afterFind hooks', () => {
36593659
acl.setRoleWriteAccess('admin', true);
36603660
obj.setACL(acl);
36613661

3662+
const testDate = new Date('2025-01-01T00:00:00.000Z');
3663+
obj.set('dateField', testDate);
3664+
36623665
const json = toJSONwithObjects(obj, 'Test');
36633666

36643667
expect(json.ACL).toBeDefined();
36653668
expect(json.ACL instanceof Parse.ACL).toBe(false);
36663669
expect(json.ACL.constructor).toBe(Object);
36673670
expect(json.ACL['*']).toEqual({ read: true });
36683671
expect(json.ACL['role:admin']).toEqual({ write: true });
3672+
3673+
expect(Utils.isDate(json.dateField)).toBe(true);
3674+
expect(json.dateField).toEqual(testDate);
36693675
});
36703676

36713677
it('should return valid ACL with directAccess enabled when afterFind hook calls setACL()', async () => {

src/triggers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export function toJSONwithObjects(object, className) {
195195
for (const key in pending) {
196196
const val = object.get(key);
197197
if (!val || !val._toFullJSON) {
198-
toJSON[key] = val && typeof val.toJSON === 'function' ? val.toJSON() : val;
198+
toJSON[key] = val instanceof Parse.ACL ? val.toJSON() : val;
199199
continue;
200200
}
201201
toJSON[key] = val._toFullJSON();

0 commit comments

Comments
 (0)