Skip to content
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

fix: Parse.Object.get returns array instead of object if key name is number-like #2201

Merged
merged 15 commits into from
Jul 7, 2024
34 changes: 34 additions & 0 deletions integration/test/ParseObjectTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2056,6 +2056,40 @@ describe('Parse Object', () => {
expect(obj.get('string')).toBeInstanceOf(String);
});

fit('returns correct field values', async () => {
const values = [
// { field: 'string', value: 'string' },
// { field: 'number', value: 1 },
// { field: 'boolean', value: true },
// { field: 'array', value: [1, 2, 3] },
// { field: 'object', value: { key: 'value' } },
// { field: 'object', value: { key1: 'value1', key2: 'value2' } },
// { field: 'object', value: { key1: 1, key2: 2 } },
{ field: 'object', value: { '1x1': 1 } },
mtrezza marked this conversation as resolved.
Show resolved Hide resolved
{ field: 'object', value: { '1x1': 1, '2': 2 } },
{ field: 'object', value: { '1': 1 } },
mtrezza marked this conversation as resolved.
Show resolved Hide resolved
// { field: 'date', value: new Date() },
// {
// field: 'file',
// value: Parse.File.fromJSON({
// __type: 'File',
// name: 'name',
// url: 'http://localhost:1337/parse/files/integration/name',
// }),
// },
// { field: 'geoPoint', value: new Parse.GeoPoint(40, -30) },
// { field: 'bytes', value: { __type: 'Bytes', base64: 'ZnJveW8=' } },
];
for (const value of values) {
const object = new TestObject();
object.set(value.field, value.value);
await object.save();
const query = new Parse.Query(TestObject);
const objectAgain = await query.get(object.id);
expect(objectAgain.get(value.field)).toEqual(value.value);
}
});

describe('allowCustomObjectId', () => {
it('can save without setting an objectId', async () => {
await reconfigureServer({ allowCustomObjectId: true });
Expand Down
2 changes: 1 addition & 1 deletion src/ObjectStateMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export function commitServerChanges(
typeof val === 'object' &&
!Array.isArray(val) &&
Object.keys(val).length > 0 &&
Object.keys(val).some(k => !isNaN(parseInt(k))) &&
Object.keys(val).every(k => k === String(Number(k)) && Number.isInteger(Number(k))) &&
mtrezza marked this conversation as resolved.
Show resolved Hide resolved
!['sentPerUTCOffset', 'failedPerUTCOffset'].includes(attr)
) {
val = Object.values(val);
Expand Down
Loading