@@ -3,7 +3,6 @@ package yqlib
3
3
import (
4
4
"container/list"
5
5
"fmt"
6
- "strconv"
7
6
8
7
"github.com/elliotchance/orderedmap"
9
8
yaml "gopkg.in/yaml.v3"
@@ -57,7 +56,7 @@ func traverse(context Context, matchingNode *CandidateNode, operation *Operation
57
56
switch value .Kind {
58
57
case yaml .MappingNode :
59
58
log .Debug ("its a map with %v entries" , len (value .Content )/ 2 )
60
- return traverseMap (context , matchingNode , operation .StringValue , operation .Preferences .(traversePreferences ), false )
59
+ return traverseMap (context , matchingNode , createStringScalarNode ( operation .StringValue ) , operation .Preferences .(traversePreferences ), false )
61
60
62
61
case yaml .SequenceNode :
63
62
log .Debug ("its a sequence of %v things!" , len (value .Content ))
@@ -131,11 +130,8 @@ func traverseArrayIndices(context Context, matchingNode *CandidateNode, indicesT
131
130
node .Tag = ""
132
131
node .Kind = yaml .SequenceNode
133
132
//check that the indices are numeric, if not, then we should create an object
134
- if len (indicesToTraverse ) != 0 {
135
- _ , err := strconv .ParseInt (indicesToTraverse [0 ].Value , 10 , 64 )
136
- if err != nil {
137
- node .Kind = yaml .MappingNode
138
- }
133
+ if len (indicesToTraverse ) != 0 && indicesToTraverse [0 ].Tag != "!!int" {
134
+ node .Kind = yaml .MappingNode
139
135
}
140
136
}
141
137
@@ -155,14 +151,14 @@ func traverseArrayIndices(context Context, matchingNode *CandidateNode, indicesT
155
151
156
152
func traverseMapWithIndices (context Context , candidate * CandidateNode , indices []* yaml.Node , prefs traversePreferences ) (* list.List , error ) {
157
153
if len (indices ) == 0 {
158
- return traverseMap (context , candidate , "" , prefs , true )
154
+ return traverseMap (context , candidate , createStringScalarNode ( "" ) , prefs , true )
159
155
}
160
156
161
157
var matchingNodeMap = list .New ()
162
158
163
159
for _ , indexNode := range indices {
164
160
log .Debug ("traverseMapWithIndices: %v" , indexNode .Value )
165
- newNodes , err := traverseMap (context , candidate , indexNode . Value , prefs , false )
161
+ newNodes , err := traverseMap (context , candidate , indexNode , prefs , false )
166
162
if err != nil {
167
163
return nil , err
168
164
}
@@ -224,9 +220,9 @@ func keyMatches(key *yaml.Node, wantedKey string) bool {
224
220
return matchKey (key .Value , wantedKey )
225
221
}
226
222
227
- func traverseMap (context Context , matchingNode * CandidateNode , key string , prefs traversePreferences , splat bool ) (* list.List , error ) {
223
+ func traverseMap (context Context , matchingNode * CandidateNode , keyNode * yaml. Node , prefs traversePreferences , splat bool ) (* list.List , error ) {
228
224
var newMatches = orderedmap .NewOrderedMap ()
229
- err := doTraverseMap (newMatches , matchingNode , key , prefs , splat )
225
+ err := doTraverseMap (newMatches , matchingNode , keyNode . Value , prefs , splat )
230
226
231
227
if err != nil {
232
228
return nil , err
@@ -235,7 +231,7 @@ func traverseMap(context Context, matchingNode *CandidateNode, key string, prefs
235
231
if ! prefs .DontAutoCreate && ! context .DontAutoCreate && newMatches .Len () == 0 {
236
232
//no matches, create one automagically
237
233
valueNode := & yaml.Node {Tag : "!!null" , Kind : yaml .ScalarNode , Value : "null" }
238
- keyNode := & yaml. Node { Kind : yaml . ScalarNode , Value : key }
234
+
239
235
node := matchingNode .Node
240
236
241
237
if len (node .Content ) == 0 {
0 commit comments