Parser will allow a table or vector to have a trailing comma.

Unless in --strict-json mode.
Also added strict_json option to the parser, which in
addition controls if field names without quotes are allowed.

Change-Id: Id56fe5c780bdb9170958050ffa8fa23cf2babe95
Tested: on Linux.
This commit is contained in:
Wouter van Oortmerssen
2015-01-16 16:57:04 -08:00
parent e568f17096
commit 6c2dc41e0d
6 changed files with 25 additions and 15 deletions

View File

@@ -249,7 +249,7 @@ void ParseProtoTest() {
"tests/prototest/test.golden", false, &goldenfile), true);
// Parse proto.
flatbuffers::Parser parser(true);
flatbuffers::Parser parser(false, true);
TEST_EQ(parser.Parse(protofile.c_str(), nullptr), true);
// Generate fbs.
@@ -493,8 +493,9 @@ void FuzzTest2() {
}
// Test that parser errors are actually generated.
void TestError(const char *src, const char *error_substr) {
flatbuffers::Parser parser;
void TestError(const char *src, const char *error_substr,
bool strict_json = false) {
flatbuffers::Parser parser(strict_json);
TEST_EQ(parser.Parse(src), false); // Must signal error
// Must be the error we're expecting
TEST_NOTNULL(strstr(parser.error_.c_str(), error_substr));
@@ -522,6 +523,9 @@ void ErrorTest() {
TestError("union Z { X } table X { Y:Z; } root_type X; { Y_type: 99, Y: {",
"type id");
TestError("table X { Y:int; } root_type X; { Z:", "unknown field");
TestError("table X { Y:int; } root_type X; { Y:", "string constant", true);
TestError("table X { Y:int; } root_type X; { \"Y\":1, }", "string constant",
true);
TestError("struct X { Y:int; Z:int; } table W { V:X; } root_type W; "
"{ V:{ Y:1 } }", "incomplete");
TestError("enum E:byte { A } table X { Y:E; } root_type X; { Y:U }",