json: verify that objects have keys [GH-128]

This commit is contained in:
Mitchell Hashimoto 2016-06-21 12:57:45 -07:00
parent da48636430
commit 685b5f7416
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
3 changed files with 11 additions and 0 deletions

View File

@ -128,6 +128,12 @@ func (p *Parser) objectKey() ([]*ast.ObjectKey, error) {
Token: p.tok.HCLToken(),
})
case token.COLON:
// If we have a zero keycount it means that we never got
// an object key, i.e. `{ :`. This is a syntax error.
if keyCount == 0 {
return nil, fmt.Errorf("expected: STRING got: %s", p.tok.Type)
}
// Done
return keys, nil
case token.ILLEGAL:

View File

@ -311,6 +311,10 @@ func TestParse(t *testing.T) {
"types.json",
false,
},
{
"bad_input_128.json",
true,
},
}
const fixtureDir = "./test-fixtures"

View File

@ -0,0 +1 @@
{:{