Skip to content

Commit 62e7c3a

Browse files
committed
Parse: allow trailing commas in array (not just object)
1 parent df0433a commit 62e7c3a

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

parser_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ func TestParser(t *testing.T) {
9393
if test.errors && errors == nil {
9494
t.Errorf("%s: got no parse errors, want parse errors", label)
9595
}
96+
if !test.errors && errors != nil {
97+
t.Errorf("%s: got parse errors %v, want no parse errors", label, errors)
98+
}
9699
if string(output) != test.want {
97100
t.Errorf("%s: got output %s, want %s", label, output, test.want)
98101
}

visitor.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ func (w *walker) parseArray() bool {
260260
}
261261
w.onSeparator(',')
262262
w.scanNext() // consume comma
263+
if w.scanner.Token() == CloseBracketToken && w.options.TrailingCommas {
264+
break
265+
}
263266
} else if needsComma {
264267
w.handleError(CommaExpected, nil, nil)
265268
}

0 commit comments

Comments
 (0)