Merge pull request #422 from hashicorp/alisdair/hclwrite-empty-labels
hclwrite: Allow blank quoted string block labels
This commit is contained in:
commit
253a71d65c
@ -159,6 +159,12 @@ func (bl *blockLabels) Current() []string {
|
||||
if !diags.HasErrors() {
|
||||
labelNames = append(labelNames, labelString)
|
||||
}
|
||||
} else if len(tokens) == 2 &&
|
||||
tokens[0].Type == hclsyntax.TokenOQuote &&
|
||||
tokens[1].Type == hclsyntax.TokenCQuote {
|
||||
// An open quote followed immediately by a closing quote is a
|
||||
// valid but unusual blank string label.
|
||||
labelNames = append(labelNames, "")
|
||||
}
|
||||
|
||||
default:
|
||||
|
@ -107,6 +107,13 @@ escape "\u0041" {
|
||||
`,
|
||||
[]string{"\u0041"},
|
||||
},
|
||||
{
|
||||
`
|
||||
blank "" {
|
||||
}
|
||||
`,
|
||||
[]string{""},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
@ -414,7 +421,7 @@ func TestBlockSetLabels(t *testing.T) {
|
||||
{
|
||||
`foo "hoge" /* foo */ "" {}`,
|
||||
"foo",
|
||||
[]string{"hoge"},
|
||||
[]string{"hoge", ""},
|
||||
[]string{"fuga"}, // force quoted form even if the old one is unquoted.
|
||||
Tokens{
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user