json: Detect and report extraneous data at EOF
This commit is contained in:
parent
0ef4932962
commit
eca76d650c
@ -19,6 +19,14 @@ func parseFileContent(buf []byte, filename string) (node, zcl.Diagnostics) {
|
|||||||
})
|
})
|
||||||
p := newPeeker(tokens)
|
p := newPeeker(tokens)
|
||||||
node, diags := parseValue(p)
|
node, diags := parseValue(p)
|
||||||
|
if len(diags) == 0 && p.Peek().Type != tokenEOF {
|
||||||
|
diags = diags.Append(&zcl.Diagnostic{
|
||||||
|
Severity: zcl.DiagError,
|
||||||
|
Summary: "Extraneous data after value",
|
||||||
|
Detail: "Extra characters appear after the JSON value.",
|
||||||
|
Subject: p.Peek().Range.Ptr(),
|
||||||
|
})
|
||||||
|
}
|
||||||
if diags.HasErrors() {
|
if diags.HasErrors() {
|
||||||
// Don't return a node if there were errors during parsing.
|
// Don't return a node if there were errors during parsing.
|
||||||
return nil, diags
|
return nil, diags
|
||||||
|
@ -188,6 +188,11 @@ func TestParse(t *testing.T) {
|
|||||||
nil,
|
nil,
|
||||||
1,
|
1,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
`1 2`,
|
||||||
|
nil,
|
||||||
|
1,
|
||||||
|
},
|
||||||
|
|
||||||
// Objects
|
// Objects
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user