Skip to content

Commit 87dcd53

Browse files
committed
case insensitive lookup
1 parent 8aabf06 commit 87dcd53

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

apps/sim/executor/utils/block-reference.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,34 @@ function getProperties(schema: unknown): Record<string, unknown> | undefined {
5353
: undefined
5454
}
5555

56+
function getFieldCaseInsensitive(
57+
obj: Record<string, unknown>,
58+
fieldName: string
59+
): unknown | undefined {
60+
if (fieldName in obj) {
61+
return obj[fieldName]
62+
}
63+
const lowerName = fieldName.toLowerCase()
64+
for (const key of Object.keys(obj)) {
65+
if (key.toLowerCase() === lowerName) {
66+
return obj[key]
67+
}
68+
}
69+
return undefined
70+
}
71+
5672
function lookupField(schema: unknown, fieldName: string): unknown | undefined {
5773
if (typeof schema !== 'object' || schema === null) return undefined
5874
const typed = schema as Record<string, unknown>
5975

60-
if (fieldName in typed) {
61-
return typed[fieldName]
76+
const direct = getFieldCaseInsensitive(typed, fieldName)
77+
if (direct !== undefined) {
78+
return direct
6279
}
6380

6481
const props = getProperties(schema)
65-
if (props && fieldName in props) {
66-
return props[fieldName]
82+
if (props) {
83+
return getFieldCaseInsensitive(props, fieldName)
6784
}
6885

6986
return undefined

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ export interface Resolver {
2020
* navigatePath({a: {b: {c: 1}}}, ['a', 'b', 'c']) => 1
2121
* navigatePath({items: [{name: 'test'}]}, ['items', '0', 'name']) => 'test'
2222
*/
23+
function getPropertyCaseInsensitive(obj: Record<string, unknown>, key: string): unknown {
24+
if (key in obj) {
25+
return obj[key]
26+
}
27+
const lowerKey = key.toLowerCase()
28+
for (const k of Object.keys(obj)) {
29+
if (k.toLowerCase() === lowerKey) {
30+
return obj[k]
31+
}
32+
}
33+
return undefined
34+
}
35+
2336
export function navigatePath(obj: any, path: string[]): any {
2437
let current = obj
2538
for (const part of path) {
@@ -30,7 +43,10 @@ export function navigatePath(obj: any, path: string[]): any {
3043
const arrayMatch = part.match(/^([^[]+)(\[.+)$/)
3144
if (arrayMatch) {
3245
const [, prop, bracketsPart] = arrayMatch
33-
current = current[prop]
46+
current =
47+
typeof current === 'object' && current !== null
48+
? getPropertyCaseInsensitive(current, prop)
49+
: undefined
3450
if (current === undefined || current === null) {
3551
return undefined
3652
}
@@ -49,7 +65,10 @@ export function navigatePath(obj: any, path: string[]): any {
4965
const index = Number.parseInt(part, 10)
5066
current = Array.isArray(current) ? current[index] : undefined
5167
} else {
52-
current = current[part]
68+
current =
69+
typeof current === 'object' && current !== null
70+
? getPropertyCaseInsensitive(current, part)
71+
: undefined
5372
}
5473
}
5574
return current

0 commit comments

Comments
 (0)