mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-12 12:55:47 +02:00
Return an error if some node in the path is not a dictionary
This commit is contained in:
parent
7fb86d6e9c
commit
6acabba417
2 changed files with 12 additions and 0 deletions
|
@ -52,6 +52,10 @@ func updateYamlNode(node *yaml.Node, path []string, value string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if node.Kind != yaml.MappingNode {
|
||||||
|
return errors.New("yaml node in path is not a dictionary")
|
||||||
|
}
|
||||||
|
|
||||||
key := path[0]
|
key := path[0]
|
||||||
for i := 0; i < len(node.Content)-1; i += 2 {
|
for i := 0; i < len(node.Content)-1; i += 2 {
|
||||||
if node.Content[i].Value == key {
|
if node.Content[i].Value == key {
|
||||||
|
|
|
@ -74,6 +74,14 @@ func TestUpdateYamlValue(t *testing.T) {
|
||||||
expectedOut: "foo: [1, 2, 3]\n",
|
expectedOut: "foo: [1, 2, 3]\n",
|
||||||
expectedErr: "yaml node is not a scalar",
|
expectedErr: "yaml node is not a scalar",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "not all path elements are dictionaries",
|
||||||
|
in: "foo:\n bar: [1, 2, 3]\n",
|
||||||
|
path: []string{"foo", "bar", "baz"},
|
||||||
|
value: "qux",
|
||||||
|
expectedOut: "foo:\n bar: [1, 2, 3]\n",
|
||||||
|
expectedErr: "yaml node in path is not a dictionary",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue