fix(evaluators): fix number lead key in variable path (#1976)
This commit is contained in:
parent
295faf569d
commit
9076a1d4e4
@ -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);
|
||||
});
|
||||
});
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user