json: verify that objects have keys [GH-128]
This commit is contained in:
parent
da48636430
commit
685b5f7416
@ -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:
|
||||
|
@ -311,6 +311,10 @@ func TestParse(t *testing.T) {
|
||||
"types.json",
|
||||
false,
|
||||
},
|
||||
{
|
||||
"bad_input_128.json",
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
const fixtureDir = "./test-fixtures"
|
||||
|
1
json/parser/test-fixtures/bad_input_128.json
Normal file
1
json/parser/test-fixtures/bad_input_128.json
Normal file
@ -0,0 +1 @@
|
||||
{:{
|
Loading…
Reference in New Issue
Block a user