From 9f8f82dfe8a0a0f37c197778cc8f794af44ed3e2 Mon Sep 17 00:00:00 2001 From: Stephen Levine Date: Thu, 10 Sep 2020 21:19:18 -0400 Subject: [PATCH] Fix index exception when setting empty Tree slice (#425) --- toml.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/toml.go b/toml.go index ec2a325..cbb89a9 100644 --- a/toml.go +++ b/toml.go @@ -339,7 +339,8 @@ func (t *Tree) SetPathWithOptions(keys []string, opts SetOptions, value interfac // go to most recent element if len(node) == 0 { // create element if it does not exist - subtree.values[intermediateKey] = append(node, newTreeWithPosition(Position{Line: t.position.Line + i, Col: t.position.Col})) + node = append(node, newTreeWithPosition(Position{Line: t.position.Line + i, Col: t.position.Col})) + subtree.values[intermediateKey] = node } subtree = node[len(node)-1] }