Skip to content

Commit 6fac012

Browse files
committed
fix multi index
1 parent 7fc7b0f commit 6fac012

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

apps/sim/executor/variables/resolvers/reference.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,28 @@ export function navigatePath(obj: any, path: string[]): any {
2727
return undefined
2828
}
2929

30-
// Handle array indexing like "items[0]" or just numeric indices
31-
const arrayMatch = part.match(/^([^[]+)\[(\d+)\](.*)$/)
30+
const arrayMatch = part.match(/^([^[]+)(\[.+)$/)
3231
if (arrayMatch) {
33-
// Handle complex array access like "items[0]"
34-
const [, prop, index] = arrayMatch
32+
const [, prop, bracketsPart] = arrayMatch
3533
current = current[prop]
3634
if (current === undefined || current === null) {
3735
return undefined
3836
}
39-
const idx = Number.parseInt(index, 10)
40-
current = Array.isArray(current) ? current[idx] : undefined
37+
38+
const indices = bracketsPart.match(/\[(\d+)\]/g)
39+
if (indices) {
40+
for (const indexMatch of indices) {
41+
if (current === null || current === undefined) {
42+
return undefined
43+
}
44+
const idx = Number.parseInt(indexMatch.slice(1, -1), 10)
45+
current = Array.isArray(current) ? current[idx] : undefined
46+
}
47+
}
4148
} else if (/^\d+$/.test(part)) {
42-
// Handle plain numeric index
4349
const index = Number.parseInt(part, 10)
4450
current = Array.isArray(current) ? current[index] : undefined
4551
} else {
46-
// Handle regular property access
4752
current = current[part]
4853
}
4954
}

0 commit comments

Comments
 (0)