@@ -116,9 +116,15 @@ func getKey(s string) (string, string) {
116
116
func access (current interface {}, selector string , value interface {}, isSet bool ) interface {} {
117
117
thisSel , nextSel := getKey (selector )
118
118
119
- index := - 1
120
- if strings .Contains (thisSel , "[" ) {
119
+ indexes := []int {}
120
+ for strings .Contains (thisSel , "[" ) {
121
+ prevSel := thisSel
122
+ index := - 1
121
123
index , thisSel = getIndex (thisSel )
124
+ indexes = append (indexes , index )
125
+ if prevSel == thisSel {
126
+ break
127
+ }
122
128
}
123
129
124
130
if curMap , ok := current .(Map ); ok {
@@ -134,7 +140,7 @@ func access(current interface{}, selector string, value interface{}, isSet bool)
134
140
}
135
141
136
142
_ , ok := curMSI [thisSel ].(map [string ]interface {})
137
- if (curMSI [thisSel ] == nil || ! ok ) && index == - 1 && isSet {
143
+ if (curMSI [thisSel ] == nil || ! ok ) && len ( indexes ) == 0 && isSet {
138
144
curMSI [thisSel ] = map [string ]interface {}{}
139
145
}
140
146
@@ -144,15 +150,23 @@ func access(current interface{}, selector string, value interface{}, isSet bool)
144
150
}
145
151
146
152
// do we need to access the item of an array?
147
- if index > - 1 {
148
- if array , ok := interSlice (current ); ok {
149
- if index < len (array ) {
150
- current = array [index ]
151
- } else {
152
- current = nil
153
+ if len (indexes ) > 0 {
154
+ num := len (indexes )
155
+ for num > 0 {
156
+ num --
157
+ index := indexes [num ]
158
+ indexes = indexes [:num ]
159
+ if array , ok := interSlice (current ); ok {
160
+ if index < len (array ) {
161
+ current = array [index ]
162
+ } else {
163
+ current = nil
164
+ break
165
+ }
153
166
}
154
167
}
155
168
}
169
+
156
170
if nextSel != "" {
157
171
current = access (current , nextSel , value , isSet )
158
172
}
0 commit comments