Skip to content

Commit

Permalink
fix: getSchema returning undefined doesn't break setIn (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
monkindey authored and janryWang committed Aug 19, 2019
1 parent 0f7edab commit da1f7a2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/utils/src/__tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ test('test setIn auto create array', () => {
).toBeTruthy()
})

test('getSchema return undefined', () => {
const value = {}
setIn(value, 'array.0.bb.2', 'hello world', () => {})

expect(
isEqual(value, {
array: [
{
bb: [undefined, undefined, 'hello world']
}
]
})
).toBeTruthy()
})

test('test setIn dose not affect other items', () => {
const value = {
aa: [
Expand Down
3 changes: 2 additions & 1 deletion packages/utils/src/accessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,8 @@ function _setIn(
if (/^\d+$/.test(pathArr[i + 1 + ''])) {
if (getSchema) {
const schema = getSchema(pathArr.slice(0, i) as string[])
if (schema.type === 'array') {

if (!schema || schema.type === 'array') {
obj[p] = []
} else {
obj[p] = {}
Expand Down

0 comments on commit da1f7a2

Please sign in to comment.