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,
|
nil,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"unterminated_brace.hcl",
|
||||||
|
true,
|
||||||
|
nil,
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"object_list.json",
|
"object_list.json",
|
||||||
false,
|
false,
|
||||||
@ -629,7 +635,7 @@ content {
|
|||||||
func TestDecode_NestedNode(t *testing.T) {
|
func TestDecode_NestedNode(t *testing.T) {
|
||||||
// given
|
// given
|
||||||
var value struct {
|
var value struct {
|
||||||
Nested struct {
|
Nested struct {
|
||||||
Content ast.Node
|
Content ast.Node
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -661,4 +667,3 @@ nested "content" {
|
|||||||
t.Errorf("expected mapping to be returned")
|
t.Errorf("expected mapping to be returned")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,6 +246,11 @@ func (p *Parser) objectType() (*ast.ObjectType, error) {
|
|||||||
return nil, err
|
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.List = l
|
||||||
o.Rbrace = p.tok.Pos // advanced via parseObjectList
|
o.Rbrace = p.tok.Pos // advanced via parseObjectList
|
||||||
return o, nil
|
return o, nil
|
||||||
|
@ -156,6 +156,7 @@ func TestObjectType(t *testing.T) {
|
|||||||
item, err := p.objectItem()
|
item, err := p.objectItem()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// we know that the ObjectKey name is foo for all cases, what matters
|
// 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)
|
obj, ok := item.Val.(*ast.ObjectType)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Errorf("node should be of type LiteralType, got: %T", item.Val)
|
t.Errorf("node should be of type LiteralType, got: %T", item.Val)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the total length of items are correct
|
// check if the total length of items are correct
|
||||||
@ -297,6 +299,10 @@ func TestParse(t *testing.T) {
|
|||||||
"missing_braces.hcl",
|
"missing_braces.hcl",
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"unterminated_object.hcl",
|
||||||
|
true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const fixtureDir = "./test-fixtures"
|
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