Fix json parser comma after empty object case

master
Marc Tiehuis 2018-06-08 17:43:13 +12:00
parent f0b6dac1f2
commit ffb089a9f5
2 changed files with 23 additions and 5 deletions

View File

@ -324,7 +324,9 @@ pub const StreamingParser = struct {
p.complete = true;
p.state = State.TopLevelEnd;
},
else => {},
else => {
p.state = State.ValueEnd;
},
}
token.* = Token.initMarker(Token.Id.ObjectEnd);
@ -348,7 +350,9 @@ pub const StreamingParser = struct {
p.complete = true;
p.state = State.TopLevelEnd;
},
else => {},
else => {
p.state = State.ValueEnd;
},
}
token.* = Token.initMarker(Token.Id.ArrayEnd);
@ -970,7 +974,7 @@ pub fn validate(s: []const u8) bool {
var token1: ?Token = undefined;
var token2: ?Token = undefined;
p.feed(c, *token1, *token2) catch |err| {
p.feed(c, &token1, &token2) catch |err| {
return false;
};
}
@ -978,6 +982,10 @@ pub fn validate(s: []const u8) bool {
return p.complete;
}
test "json validate" {
debug.assert(validate("{}"));
}
const Allocator = std.mem.Allocator;
const ArenaAllocator = std.heap.ArenaAllocator;
const ArrayList = std.ArrayList;
@ -1230,7 +1238,7 @@ pub const Parser = struct {
_ = p.stack.pop();
p.state = State.ObjectKey;
},
else => {
Token.Id.ObjectEnd, Token.Id.ArrayEnd => {
unreachable;
},
}
@ -1270,7 +1278,7 @@ pub const Parser = struct {
Token.Id.Null => {
try array.append(Value.Null);
},
else => {
Token.Id.ObjectEnd => {
unreachable;
},
}

View File

@ -17,6 +17,16 @@ fn any(comptime s: []const u8) void {
std.debug.assert(true);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Additional tests not part of test JSONTestSuite.
test "y_trailing_comma_after_empty" {
ok(
\\{"1":[],"2":{},"3":"4"}
);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
test "y_array_arraysWithSpaces" {