Skip to content

feat: Allow Parse.Object field names to begin with underscore _ to access internal fields of Parse Server #2475

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

Merged
merged 3 commits into from
Mar 5, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions integration/test/ParseObjectTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ describe('Parse Object', () => {
});

it('cannot create invalid key names', async () => {
const error = new Parse.Error(Parse.Error.INVALID_KEY_NAME, `Invalid key name: "foo^bar"`);
const error = new Parse.Error(Parse.Error.INVALID_KEY_NAME, 'Invalid key name: foo^bar');
const item = new Parse.Object('Item');
expect(() => {
item.set({ 'foo^bar': 'baz' });
Expand All @@ -559,7 +559,7 @@ describe('Parse Object', () => {
const item = new Parse.Object('Item');
expect(() => {
item.set({ foobar: 'baz', 'foo^bar': 'baz' });
}).toThrow(new Parse.Error(Parse.Error.INVALID_KEY_NAME, `Invalid key name: "foo^bar"`));
}).toThrow(new Parse.Error(Parse.Error.INVALID_KEY_NAME, 'Invalid key name: foo^bar'));
});

it('can unset fields', done => {
Expand Down
4 changes: 2 additions & 2 deletions src/ParseObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1099,8 +1099,8 @@ class ParseObject {
return new ParseError(ParseError.OTHER_CAUSE, 'ACL must be a Parse ACL.');
}
for (const key in attrs) {
if (!/^[A-Za-z][0-9A-Za-z_.]*$/.test(key)) {
return new ParseError(ParseError.INVALID_KEY_NAME, `Invalid key name: "${key}"`);
if (!/^[A-Za-z_][0-9A-Za-z_.]*$/.test(key)) {
return new ParseError(ParseError.INVALID_KEY_NAME, `Invalid key name: ${key}`);
}
}
return false;
Expand Down
6 changes: 4 additions & 2 deletions src/__tests__/ParseObject-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ describe('ParseObject', () => {
o.validate({
'invalid!key': 12,
})
).toEqual(new ParseError(ParseError.INVALID_KEY_NAME, `Invalid key name: "invalid!key"`));
).toEqual(new ParseError(ParseError.INVALID_KEY_NAME, 'Invalid key name: invalid!key'));

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

it('ignores validation if ignoreValidation option is passed to set()', () => {
Expand All @@ -1003,6 +1003,8 @@ describe('ParseObject', () => {
expect(o.isValid()).toBe(true);
o.set('someKey', 'someValue');
expect(o.isValid()).toBe(true);
o.set('_internalField', 'allow_underscore');
expect(o.isValid()).toBe(true);
o._finishFetch({
objectId: 'O3',
'invalid!key': 'oops',
Expand Down
Loading