Skip to content

Commit 08e43ba

Browse files
authored
feat: Allow Parse.Object field names to begin with underscore _ to access internal fields of Parse Server (#2475)
1 parent 60c8398 commit 08e43ba

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

integration/test/ParseObjectTest.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ describe('Parse Object', () => {
547547
});
548548

549549
it('cannot create invalid key names', async () => {
550-
const error = new Parse.Error(Parse.Error.INVALID_KEY_NAME, `Invalid key name: "foo^bar"`);
550+
const error = new Parse.Error(Parse.Error.INVALID_KEY_NAME, 'Invalid key name: foo^bar');
551551
const item = new Parse.Object('Item');
552552
expect(() => {
553553
item.set({ 'foo^bar': 'baz' });
@@ -559,7 +559,7 @@ describe('Parse Object', () => {
559559
const item = new Parse.Object('Item');
560560
expect(() => {
561561
item.set({ foobar: 'baz', 'foo^bar': 'baz' });
562-
}).toThrow(new Parse.Error(Parse.Error.INVALID_KEY_NAME, `Invalid key name: "foo^bar"`));
562+
}).toThrow(new Parse.Error(Parse.Error.INVALID_KEY_NAME, 'Invalid key name: foo^bar'));
563563
});
564564

565565
it('can unset fields', done => {

src/ParseObject.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1099,8 +1099,8 @@ class ParseObject {
10991099
return new ParseError(ParseError.OTHER_CAUSE, 'ACL must be a Parse ACL.');
11001100
}
11011101
for (const key in attrs) {
1102-
if (!/^[A-Za-z][0-9A-Za-z_.]*$/.test(key)) {
1103-
return new ParseError(ParseError.INVALID_KEY_NAME, `Invalid key name: "${key}"`);
1102+
if (!/^[A-Za-z_][0-9A-Za-z_.]*$/.test(key)) {
1103+
return new ParseError(ParseError.INVALID_KEY_NAME, `Invalid key name: ${key}`);
11041104
}
11051105
}
11061106
return false;

src/__tests__/ParseObject-test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ describe('ParseObject', () => {
965965
o.validate({
966966
'invalid!key': 12,
967967
})
968-
).toEqual(new ParseError(ParseError.INVALID_KEY_NAME, `Invalid key name: "invalid!key"`));
968+
).toEqual(new ParseError(ParseError.INVALID_KEY_NAME, 'Invalid key name: invalid!key'));
969969

970970
expect(
971971
o.validate({
@@ -988,7 +988,7 @@ describe('ParseObject', () => {
988988
expect(o.set('ACL', { '*': { read: true, write: false } })).toBe(o);
989989
expect(() => {
990990
o.set('$$$', 'o_O');
991-
}).toThrow(new ParseError(ParseError.INVALID_KEY_NAME, `Invalid key name: "$$$"`));
991+
}).toThrow(new ParseError(ParseError.INVALID_KEY_NAME, 'Invalid key name: $$$'));
992992
});
993993

994994
it('ignores validation if ignoreValidation option is passed to set()', () => {
@@ -1003,6 +1003,8 @@ describe('ParseObject', () => {
10031003
expect(o.isValid()).toBe(true);
10041004
o.set('someKey', 'someValue');
10051005
expect(o.isValid()).toBe(true);
1006+
o.set('_internalField', 'allow_underscore');
1007+
expect(o.isValid()).toBe(true);
10061008
o._finishFetch({
10071009
objectId: 'O3',
10081010
'invalid!key': 'oops',

0 commit comments

Comments
 (0)