Skip to content

Commit 7a08047

Browse files
authored
Fix #5654 (#5664)
* Fix #5654 * fix tests * throw error instead
1 parent a58653a commit 7a08047

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

spec/ParseObject.spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,4 +2068,19 @@ describe('Parse.Object testing', () => {
20682068

20692069
done();
20702070
});
2071+
2072+
it('isNew in cloud code', async () => {
2073+
Parse.Cloud.beforeSave('CloudCodeIsNew', req => {
2074+
expect(req.object.isNew()).toBeTruthy();
2075+
expect(req.object.id).toBeUndefined();
2076+
});
2077+
2078+
Parse.Cloud.afterSave('CloudCodeIsNew', req => {
2079+
expect(req.object.isNew()).toBeFalsy();
2080+
expect(req.object.id).toBeDefined();
2081+
});
2082+
2083+
const object = new Parse.Object('CloudCodeIsNew');
2084+
await object.save();
2085+
});
20712086
});

spec/rest.spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,28 @@ describe('rest create', () => {
446446
});
447447
});
448448

449+
it('cannot set id', done => {
450+
const headers = {
451+
'Content-Type': 'application/json',
452+
'X-Parse-Application-Id': 'test',
453+
'X-Parse-REST-API-Key': 'rest',
454+
};
455+
request({
456+
headers: headers,
457+
method: 'POST',
458+
url: 'http://localhost:8378/1/classes/TestObject',
459+
body: JSON.stringify({
460+
foo: 'bar',
461+
id: 'hello',
462+
}),
463+
}).then(fail, response => {
464+
const b = response.data;
465+
expect(b.code).toEqual(105);
466+
expect(b.error).toEqual('id is an invalid field name.');
467+
done();
468+
});
469+
});
470+
449471
it('test default session length', done => {
450472
const user = {
451473
username: 'asdf',

src/RestWrite.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ function RestWrite(
5252
'objectId is an invalid field name.'
5353
);
5454
}
55+
if (!query && data.id) {
56+
throw new Parse.Error(
57+
Parse.Error.INVALID_KEY_NAME,
58+
'id is an invalid field name.'
59+
);
60+
}
5561

5662
// When the operation is complete, this.response may have several
5763
// fields.

0 commit comments

Comments
 (0)