Skip to content

Commit

Permalink
fix(core): indexes need exclude incomplete number (#3437)
Browse files Browse the repository at this point in the history
  • Loading branch information
frehaiku committed Oct 8, 2022
1 parent 3f8aa1b commit d328bb3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/core/src/__tests__/array.spec.ts
Expand Up @@ -538,6 +538,21 @@ test('nest array remove', async () => {
).not.toBeUndefined()
})

test('indexes: nest path need exclude incomplete number', () => {
const form = attach(createForm())

const objPathIncludeNum = attach(
form.createField({
name: 'attr',
basePath: 'metrics.0.a.10.iconWidth50',
})
)

expect(objPathIncludeNum.indexes.length).toBe(2)
expect(objPathIncludeNum.indexes).toEqual([0, 10])
expect(objPathIncludeNum.index).toBe(10)
})

test('incomplete insertion of array elements', async () => {
const form = attach(
createForm({
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/models/BaseField.ts
Expand Up @@ -53,7 +53,7 @@ export class BaseField<Decorator = any, Component = any, TextType = any> {
}

get indexes() {
return this.path.transform(/\d/, (...args) =>
return this.path.transform(/^\d+$/, (...args) =>
args.map((index) => Number(index))
)
}
Expand Down

0 comments on commit d328bb3

Please sign in to comment.