Parser enforces closing RBRACE [GH-88]
This commit is contained in:
parent
8cc8107682
commit
1c284ec98f
@ -238,6 +238,12 @@ func TestDecode_interface(t *testing.T) {
|
||||
nil,
|
||||
},
|
||||
|
||||
{
|
||||
"unterminated_brace.hcl",
|
||||
true,
|
||||
nil,
|
||||
},
|
||||
|
||||
{
|
||||
"object_list.json",
|
||||
false,
|
||||
@ -629,7 +635,7 @@ content {
|
||||
func TestDecode_NestedNode(t *testing.T) {
|
||||
// given
|
||||
var value struct {
|
||||
Nested struct {
|
||||
Nested struct {
|
||||
Content ast.Node
|
||||
}
|
||||
}
|
||||
@ -661,4 +667,3 @@ nested "content" {
|
||||
t.Errorf("expected mapping to be returned")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -246,6 +246,11 @@ func (p *Parser) objectType() (*ast.ObjectType, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// If there is no error, we should be at a RBRACE to end the object
|
||||
if p.tok.Type != token.RBRACE {
|
||||
return nil, fmt.Errorf("object expected closing RBRACE got: %s", p.tok.Type)
|
||||
}
|
||||
|
||||
o.List = l
|
||||
o.Rbrace = p.tok.Pos // advanced via parseObjectList
|
||||
return o, nil
|
||||
|
@ -156,6 +156,7 @@ func TestObjectType(t *testing.T) {
|
||||
item, err := p.objectItem()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
continue
|
||||
}
|
||||
|
||||
// we know that the ObjectKey name is foo for all cases, what matters
|
||||
@ -163,6 +164,7 @@ func TestObjectType(t *testing.T) {
|
||||
obj, ok := item.Val.(*ast.ObjectType)
|
||||
if !ok {
|
||||
t.Errorf("node should be of type LiteralType, got: %T", item.Val)
|
||||
continue
|
||||
}
|
||||
|
||||
// check if the total length of items are correct
|
||||
@ -297,6 +299,10 @@ func TestParse(t *testing.T) {
|
||||
"missing_braces.hcl",
|
||||
true,
|
||||
},
|
||||
{
|
||||
"unterminated_object.hcl",
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
const fixtureDir = "./test-fixtures"
|
||||
|
2
hcl/parser/test-fixtures/unterminated_object.hcl
Normal file
2
hcl/parser/test-fixtures/unterminated_object.hcl
Normal file
@ -0,0 +1,2 @@
|
||||
foo "baz" {
|
||||
bar = "baz"
|
2
test-fixtures/unterminated_brace.hcl
Normal file
2
test-fixtures/unterminated_brace.hcl
Normal file
@ -0,0 +1,2 @@
|
||||
foo "baz" {
|
||||
bar = "baz"
|
Loading…
Reference in New Issue
Block a user