Added a nill check to lookup.

was causing vacuum to crash during testing.
This commit is contained in:
quobix
2024-07-09 13:32:31 -04:00
parent c9155f7ef3
commit 425b25cdd0
2 changed files with 42 additions and 1 deletions

View File

@@ -336,7 +336,7 @@ func FindKeyNodeFull(key string, nodes []*yaml.Node) (keyNode *yaml.Node, labelN
}
}
if key == v.Content[x].Value {
if len(v.Content) > 0 && key == v.Content[x].Value {
if IsNodeMap(v) {
if x+1 == len(v.Content) {
return v, v.Content[x], NodeAlias(v.Content[x])

View File

@@ -1002,6 +1002,47 @@ func TestDetermineJSONWhitespaceLength_None(t *testing.T) {
assert.Equal(t, 0, DetermineWhitespaceLength(string(someBytes)))
}
func TestFindFirstKeyNode_MergeTest(t *testing.T) {
yml := []byte(`openapi: 3.0.3
x-a: &anchor
important-field: true
x-b:
<<: *anchor
`)
var rootNode yaml.Node
_ = yaml.Unmarshal(yml, &rootNode)
k, v := FindFirstKeyNode("important-field", rootNode.Content[0].Content[5].Content, 0)
assert.NotNil(t, k)
assert.NotNil(t, v)
assert.Equal(t, "true", v.Value)
}
func TestFindKeyNodeFull_MergeTest(t *testing.T) {
yml := []byte(`openapi: 3.0.3
x-a: &anchor
important-field: true
x-b:
<<: *anchor
`)
var rootNode yaml.Node
_ = yaml.Unmarshal(yml, &rootNode)
k, l, v := FindKeyNodeFull("servers", rootNode.Content[0].Content)
assert.NotNil(t, k)
assert.NotNil(t, v)
assert.NotNil(t, l)
assert.Equal(t, "true", v.Value)
}
func TestFindFirstKeyNode_DoubleMerge(t *testing.T) {
yml := []byte(`openapi: 3.0.3