mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-14 04:25:36 +00:00
Fixed potential npe
This commit is contained in:
parent
4eaadf98d0
commit
e5948c4f16
@ -617,6 +617,27 @@ pointer: *value-pointer`
|
|||||||
test.AssertResult(t, expectedOutput, result.Output)
|
test.AssertResult(t, expectedOutput, result.Output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestReadMergeAnchorsExplodeMissingCmd(t *testing.T) {
|
||||||
|
content := `a:
|
||||||
|
<<: &anchor
|
||||||
|
c: d
|
||||||
|
e: f
|
||||||
|
`
|
||||||
|
filename := test.WriteTempYamlFile(content)
|
||||||
|
defer test.RemoveTempYamlFile(filename)
|
||||||
|
|
||||||
|
cmd := getRootCommand()
|
||||||
|
result := test.RunCmd(cmd, fmt.Sprintf("read -X %s", filename))
|
||||||
|
if result.Error != nil {
|
||||||
|
t.Error(result.Error)
|
||||||
|
}
|
||||||
|
expectedOutput := `a:
|
||||||
|
c: d
|
||||||
|
e: f
|
||||||
|
`
|
||||||
|
test.AssertResult(t, expectedOutput, result.Output)
|
||||||
|
}
|
||||||
|
|
||||||
func TestReadMergeAnchorsExplodeKeyCmd(t *testing.T) {
|
func TestReadMergeAnchorsExplodeKeyCmd(t *testing.T) {
|
||||||
content := `name: &nameField Mike
|
content := `name: &nameField Mike
|
||||||
*nameField: Great Guy`
|
*nameField: Great Guy`
|
||||||
|
17
cmd/utils.go
17
cmd/utils.go
@ -163,6 +163,9 @@ func setIfNotThere(node *yaml.Node, key string, value *yaml.Node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func applyAlias(node *yaml.Node, alias *yaml.Node) {
|
func applyAlias(node *yaml.Node, alias *yaml.Node) {
|
||||||
|
if alias == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
for index := 0; index < len(alias.Content); index = index + 2 {
|
for index := 0; index < len(alias.Content); index = index + 2 {
|
||||||
keyNode := alias.Content[index]
|
keyNode := alias.Content[index]
|
||||||
log.Debugf("applying alias key %v", keyNode.Value)
|
log.Debugf("applying alias key %v", keyNode.Value)
|
||||||
@ -185,12 +188,14 @@ func explodeNode(node *yaml.Node) error {
|
|||||||
return nil
|
return nil
|
||||||
case yaml.AliasNode:
|
case yaml.AliasNode:
|
||||||
log.Debugf("its an alias!")
|
log.Debugf("its an alias!")
|
||||||
node.Kind = node.Alias.Kind
|
if node.Alias != nil {
|
||||||
node.Style = node.Alias.Style
|
node.Kind = node.Alias.Kind
|
||||||
node.Tag = node.Alias.Tag
|
node.Style = node.Alias.Style
|
||||||
node.Content = node.Alias.Content
|
node.Tag = node.Alias.Tag
|
||||||
node.Value = node.Alias.Value
|
node.Content = node.Alias.Content
|
||||||
node.Alias = nil
|
node.Value = node.Alias.Value
|
||||||
|
node.Alias = nil
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
case yaml.MappingNode:
|
case yaml.MappingNode:
|
||||||
for index := 0; index < len(node.Content); index = index + 2 {
|
for index := 0; index < len(node.Content); index = index + 2 {
|
||||||
|
Loading…
Reference in New Issue
Block a user