@@ -189,12 +189,19 @@ func (ms *mapSource) GoString() string {
189
189
return fmt .Sprintf ("&mapSource{name:%[1]q}" , ms .name )
190
190
}
191
191
192
+ // Lookup returns a value from the map source. The lookup name may be a dot-separated path into the map.
193
+ // If that is the case, it will recursively traverse the map based on the '.' delimited sections to find
194
+ // a nested value for the key.
192
195
func (ms * mapSource ) Lookup (name string ) (any , bool ) {
193
- // nestedVal checks if the name has '.' delimiters.
194
- // If so, it tries to traverse the tree by the '.' delimited sections to find
195
- // a nested value for the key.
196
- if sections := strings .Split (name , "." ); len (sections ) > 1 {
197
- node := ms .m
196
+ sections := strings .Split (name , "." )
197
+ if name == "" || len (sections ) == 0 {
198
+ return nil , false
199
+ }
200
+
201
+ node := ms .m
202
+
203
+ // traverse into the map based on the dot-separated sections
204
+ if len (sections ) >= 2 { // the last section is the value we want, we will return it directly at the end
198
205
for _ , section := range sections [:len (sections )- 1 ] {
199
206
child , ok := node [section ]
200
207
if ! ok {
@@ -213,11 +220,11 @@ func (ms *mapSource) Lookup(name string) (any, bool) {
213
220
return nil , false
214
221
}
215
222
}
216
- if val , ok := node [sections [len (sections )- 1 ]]; ok {
217
- return val , true
218
- }
219
223
}
220
224
225
+ if val , ok := node [sections [len (sections )- 1 ]]; ok {
226
+ return val , true
227
+ }
221
228
return nil , false
222
229
}
223
230
0 commit comments