Skip to content

Commit

Permalink
Merge pull request #4103 from marmelab/fix-json-input-parsing-bug
Browse files Browse the repository at this point in the history
Fix form values sanitization messes with JSON values
  • Loading branch information
djhi committed Dec 3, 2019
2 parents 72f7f0c + c03b376 commit d73cdb5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/ra-core/src/form/sanitizeEmptyValues.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,14 @@ describe('sanitizeEmptyValues', () => {
sanitizeEmptyValues({ obj: { foo: null, foo2: 2 } }, { obj })
).toEqual({ obj: { foo: { bar: 1 }, foo2: null } });
});
it("should not ignore initial value when it's not of the same type", () => {
const initialValues = { a: 'foobar' };
const values = { a: { hello: 'world' } };
expect(sanitizeEmptyValues(initialValues, values)).toEqual({
a: { hello: 'world' },
});
expect(sanitizeEmptyValues(values, initialValues)).toEqual({
a: 'foobar',
});
});
});
1 change: 1 addition & 0 deletions packages/ra-core/src/form/sanitizeEmptyValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const sanitizeEmptyValues = (initialValues: object, values: object) => {
acc[key] = values[key];
} else if (
typeof values[key] === 'object' &&
typeof initialValues[key] === 'object' &&
values[key] !== null
) {
acc[key] = sanitizeEmptyValues(initialValues[key], values[key]);
Expand Down

0 comments on commit d73cdb5

Please sign in to comment.