@@ -189,12 +189,19 @@ func (ms *mapSource) GoString() string {
189189 return fmt .Sprintf ("&mapSource{name:%[1]q}" , ms .name )
190190}
191191
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.
192195func (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
198205 for _ , section := range sections [:len (sections )- 1 ] {
199206 child , ok := node [section ]
200207 if ! ok {
@@ -213,11 +220,11 @@ func (ms *mapSource) Lookup(name string) (any, bool) {
213220 return nil , false
214221 }
215222 }
216- if val , ok := node [sections [len (sections )- 1 ]]; ok {
217- return val , true
218- }
219223 }
220224
225+ if val , ok := node [sections [len (sections )- 1 ]]; ok {
226+ return val , true
227+ }
221228 return nil , false
222229}
223230
0 commit comments