Skip to content

Commit 5910c02

Browse files
faceappsclaude
andcommitted
fix: strip undefined values from directAccess response to match HTTP behavior
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 07cba86 commit 5910c02

2 files changed

Lines changed: 62 additions & 2 deletions

File tree

spec/ParseServerRESTController.spec.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,65 @@ describe('ParseServerRESTController', () => {
520520
);
521521
});
522522

523+
it('should strip undefined values from cloud function responses (with directAccess)', async () => {
524+
Parse.Cloud.define('returnUndefinedValues', () => {
525+
return {
526+
definedKey: 'value',
527+
undefinedKey: undefined,
528+
nested: { a: 1, b: undefined },
529+
arrayWithUndefined: [1, undefined, 3],
530+
};
531+
});
532+
533+
const res = await RESTController.request(
534+
'POST',
535+
'/functions/returnUndefinedValues',
536+
{},
537+
{ useMasterKey: true }
538+
);
539+
540+
expect(res.result.definedKey).toEqual('value');
541+
expect(res.result.undefinedKey).toBeUndefined();
542+
expect(Object.hasOwnProperty.call(res.result, 'undefinedKey')).toBe(false);
543+
expect(res.result.nested.a).toEqual(1);
544+
expect(Object.hasOwnProperty.call(res.result.nested, 'b')).toBe(false);
545+
expect(res.result.arrayWithUndefined).toEqual([1, null, 3]);
546+
});
547+
548+
it('should strip undefined values from cloud function responses (without directAccess)', async () => {
549+
Parse.Cloud.define('returnUndefinedValuesHTTP', () => {
550+
return {
551+
definedKey: 'value',
552+
undefinedKey: undefined,
553+
nested: { a: 1, b: undefined },
554+
arrayWithUndefined: [1, undefined, 3],
555+
};
556+
});
557+
558+
const serverURL = 'http://localhost:8378/1';
559+
const headers = {
560+
'Content-Type': 'application/json',
561+
'X-Parse-Application-Id': Parse.applicationId,
562+
'X-Parse-Master-Key': Parse.masterKey,
563+
};
564+
565+
const res = await request({
566+
method: 'POST',
567+
headers,
568+
url: `${serverURL}/functions/returnUndefinedValuesHTTP`,
569+
body: {},
570+
});
571+
572+
const result = res.data.result;
573+
574+
expect(result.definedKey).toEqual('value');
575+
expect(result.undefinedKey).toBeUndefined();
576+
expect(Object.hasOwnProperty.call(result, 'undefinedKey')).toBe(false);
577+
expect(result.nested.a).toEqual(1);
578+
expect(Object.hasOwnProperty.call(result.nested, 'b')).toBe(false);
579+
expect(result.arrayWithUndefined).toEqual([1, null, 3]);
580+
});
581+
523582
it('ensures sessionTokens are properly handled', async () => {
524583
const user = await Parse.User.signUp('user', 'pass');
525584
const sessionToken = user.getSessionToken();

src/ParseServerRESTController.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,11 @@ function ParseServerRESTController(applicationId, router) {
147147
.then(
148148
resp => {
149149
const { response, status, headers = {} } = resp;
150+
const strippedResponse = stripUndefined(response);
150151
if (options.returnStatus) {
151-
resolve({ ...response, _status: status, _headers: headers });
152+
resolve({ ...strippedResponse, _status: status, _headers: headers });
152153
} else {
153-
resolve(response);
154+
resolve(strippedResponse);
154155
}
155156
},
156157
err => {

0 commit comments

Comments
 (0)