Skip to content

Commit 253a71d

Browse files
authored
Merge pull request #422 from hashicorp/alisdair/hclwrite-empty-labels
hclwrite: Allow blank quoted string block labels
2 parents 3de61ec + 1818f36 commit 253a71d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

hclwrite/ast_block.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ func (bl *blockLabels) Current() []string {
159159
if !diags.HasErrors() {
160160
labelNames = append(labelNames, labelString)
161161
}
162+
} else if len(tokens) == 2 &&
163+
tokens[0].Type == hclsyntax.TokenOQuote &&
164+
tokens[1].Type == hclsyntax.TokenCQuote {
165+
// An open quote followed immediately by a closing quote is a
166+
// valid but unusual blank string label.
167+
labelNames = append(labelNames, "")
162168
}
163169

164170
default:

hclwrite/ast_block_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ escape "\u0041" {
107107
`,
108108
[]string{"\u0041"},
109109
},
110+
{
111+
`
112+
blank "" {
113+
}
114+
`,
115+
[]string{""},
116+
},
110117
}
111118

112119
for _, test := range tests {
@@ -414,7 +421,7 @@ func TestBlockSetLabels(t *testing.T) {
414421
{
415422
`foo "hoge" /* foo */ "" {}`,
416423
"foo",
417-
[]string{"hoge"},
424+
[]string{"hoge", ""},
418425
[]string{"fuga"}, // force quoted form even if the old one is unquoted.
419426
Tokens{
420427
{

0 commit comments

Comments
 (0)