Skip to content

Commit

Permalink
Fix suppress an empty token in empty list
Browse files Browse the repository at this point in the history
  • Loading branch information
minamijoyo committed Apr 4, 2022
1 parent cd38f8b commit 44e85c8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tfwrite/hclwritex.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ func SplitTokensAsList(tokens hclwrite.Tokens) []hclwrite.Tokens {
for ; end < len(tokens); end++ {
// Find a `]` token
if tokens[end].Type == hclsyntax.TokenCBrack {
ret = append(ret, tokens[begin:end])
elm := tokens[begin:end]
if len(elm) > 0 {
ret = append(ret, elm)
}
foundCBrack = true
break
}
Expand Down
20 changes: 20 additions & 0 deletions tfwrite/hclwritex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ foo {
},
ok: true,
},
{
desc: "empty string (invalid list)",
src: `
foo {
attr = ""
}
`,
want: nil,
ok: true,
},
{
desc: "empty list",
src: `
foo {
attr = []
}
`,
want: []hclwrite.Tokens{},
ok: true,
},
{
desc: "variable",
src: `
Expand Down

0 comments on commit 44e85c8

Please sign in to comment.