diff --git a/packages/core/evaluators/src/server/__tests__/index.test.ts b/packages/core/evaluators/src/server/__tests__/index.test.ts index 8d47c9080..aa5cd2a18 100644 --- a/packages/core/evaluators/src/server/__tests__/index.test.ts +++ b/packages/core/evaluators/src/server/__tests__/index.test.ts @@ -54,4 +54,9 @@ describe('evaluate', () => { const result = mathEval('{{a.1}}', { a: { 1: 1 } }); expect(result).toBe(1); }); + + it('number lead string path to object member (formula.js)', () => { + const result = formulaEval('{{a.1a}}', { a: { '1a': 1 } }); + expect(result).toBe(1); + }); }); diff --git a/packages/core/evaluators/src/utils/index.ts b/packages/core/evaluators/src/utils/index.ts index 4727dcc2a..37665ba5f 100644 --- a/packages/core/evaluators/src/utils/index.ts +++ b/packages/core/evaluators/src/utils/index.ts @@ -23,7 +23,7 @@ function replaceNumberIndex(path: string, scope: Scope): string { for (let i = 0; i < segments.length; i++) { const p = segments[i]; - if (p.match(/^\d+$/)) { + if (p[0] && '0123456789'.indexOf(p[0]) > -1) { paths.push(Array.isArray(get(scope, segments.slice(0, i))) ? `[${p}]` : `["${p}"]`); } else { if (i) {