Skip to content

Commit

Permalink
Fix: #3922 by adding a condition to the spread operator. (#3947)
Browse files Browse the repository at this point in the history
* Fix: #3922 by addind a condition to the spread operator when creating the newFormData in sanitizeDataForNewSchema(

* Add test cases to cover the changes required for the fix.

* Added CHANGELOG description of the fix.

* Add heath-freenome recommendation.

Co-authored-by: Heath C <51679588+heath-freenome@users.noreply.github.com>

---------

Co-authored-by: Heath C <51679588+heath-freenome@users.noreply.github.com>
  • Loading branch information
lindolo25 and heath-freenome authored Nov 15, 2023
1 parent 9060484 commit a87de48
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@ should change the heading of the (upcoming) version to include a major version b
## @rjsf/material-ui
- Resolve the React error caused by the propagation of the `hideError` property to the DOM element, fixing [#3945](https://github.com/rjsf-team/react-jsonschema-form/issues/3945)

## @rjsf/utils

- Update `sanitizeDataForNewSchema()` to avoid spreading strings and Arrays into the returned value when the old schema is of type `string` or `array` and the new schema is of type `object`. Fixing [#3922](https://github.com/rjsf-team/react-jsonschema-form/issues/3922)

# 5.14.1

## @rjsf/utils

- Update `sanitizeDataForNewSchema()` to avoid spreading strings and Arrays into the returned value when the old schema is of type `string` or `array` and the new schema is of type `object`. Fixing [#3922](https://github.com/rjsf-team/react-jsonschema-form/issues/3922)
- update types for `labelValue` to have more granular return types, fixing [#3946](https://github.com/rjsf-team/react-jsonschema-form/issues/3946)

## Dev / playground
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/schema/sanitizeDataForNewSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export default function sanitizeDataForNewSchema<
});

newFormData = {
...data,
...(typeof data == 'string' || Array.isArray(data) ? undefined : data),
...removeOldSchemaData,
...nestedData,
};
Expand Down
27 changes: 27 additions & 0 deletions packages/utils/test/schema/sanitizeDataForNewSchemaTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,5 +456,32 @@ export default function sanitizeDataForNewSchemaTest(testValidator: TestValidato
const formData = { foo: '1' };
expect(schemaUtils.sanitizeDataForNewSchema(newSchema, oldSchema, formData)).toEqual(formData);
});
it('returns empty object when the old schema is of type string and the new contains "property" field', () => {
const oldSchema: RJSFSchema = { type: 'string' };
const newSchema: RJSFSchema = {
properties: {
foo: {
type: 'string',
},
},
};
expect(schemaUtils.sanitizeDataForNewSchema(newSchema, oldSchema, 'qwerty')).toEqual({});
});
it('returns empty object when the old schema is of type array and the new contains "property" field', () => {
const oldSchema: RJSFSchema = {
type: 'array',
items: {
type: 'string',
},
};
const newSchema: RJSFSchema = {
properties: {
foo: {
type: 'string',
},
},
};
expect(schemaUtils.sanitizeDataForNewSchema(newSchema, oldSchema, ['qwerty', 'asdfg'])).toEqual({});
});
});
}

0 comments on commit a87de48

Please sign in to comment.