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
12 changes: 1 addition & 11 deletions src/ObjectStateMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,7 @@ export function commitServerChanges(
) {
const ParseObject = CoreManager.getParseObject();
for (const attr in changes) {
let val = changes[attr];
// Check for JSON array { '0': { something }, '1': { something } }
if (
val &&
typeof val === 'object' &&
!Array.isArray(val) &&
Object.keys(val).length > 0 &&
Object.keys(val).every(k => k === String(Number(k)) && Number.isInteger(Number(k)))
) {
val = Object.values(val);
}
const val = changes[attr];
nestedSet(serverData, attr, val);
if (
val &&
Expand Down
10 changes: 0 additions & 10 deletions src/__tests__/ObjectStateMutations-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,16 +313,6 @@ describe('ObjectStateMutations', () => {
expect(serverData).toEqual({ items: [{ count: 15 }, { count: 4 }] });
});

it('can commit nested json array changes from the server to empty serverData', () => {
const serverData = {};
const objectCache = {};
ObjectStateMutations.commitServerChanges(serverData, objectCache, {
items: { '0': { count: 20 }, '1': { count: 5 } },
});
expect(serverData).toEqual({ items: [{ count: 20 }, { count: 5 }] });
expect(objectCache).toEqual({ items: '[{"count":20},{"count":5}]' });
});

mtrezza marked this conversation as resolved.
Show resolved Hide resolved
it('can commit json array with PushStatus offset fields', () => {
const serverData = {};
const objectCache = {};
Expand Down