Fix crash on missing braces
Fixes crash reported here https://github.com/hashicorp/terraform/issues/4350
This commit is contained in:
parent
17c5c97b5a
commit
3a2d43b647
@ -151,7 +151,7 @@ func (p *Parser) objectItem() (*ast.ObjectItem, error) {
|
||||
|
||||
// do a look-ahead for line comment
|
||||
p.scan()
|
||||
if o.Val.Pos().Line == keys[0].Pos().Line && p.lineComment != nil {
|
||||
if len(keys) > 0 && o.Val.Pos().Line == keys[0].Pos().Line && p.lineComment != nil {
|
||||
o.LineComment = p.lineComment
|
||||
p.lineComment = nil
|
||||
}
|
||||
|
@ -292,6 +292,10 @@ func TestParse(t *testing.T) {
|
||||
"array_comment_2.hcl",
|
||||
true,
|
||||
},
|
||||
{
|
||||
"missing_braces.hcl",
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
const fixtureDir = "./test-fixtures"
|
||||
|
4
hcl/parser/test-fixtures/missing_braces.hcl
Normal file
4
hcl/parser/test-fixtures/missing_braces.hcl
Normal file
@ -0,0 +1,4 @@
|
||||
# should error, but not crash
|
||||
resource "template_file" "cloud_config" {
|
||||
template = "$file("${path.module}/some/path")"
|
||||
}
|
Loading…
Reference in New Issue
Block a user