diff --git a/modules/libcom/src/yajl/yajl.c b/modules/libcom/src/yajl/yajl.c index fcaf8accd..87795b173 100644 --- a/modules/libcom/src/yajl/yajl.c +++ b/modules/libcom/src/yajl/yajl.c @@ -95,6 +95,7 @@ yajl_config(yajl_handle h, int option, ...) case yajl_allow_trailing_garbage: case yajl_allow_multiple_values: case yajl_allow_partial_values: + case yajl_allow_json5: if (va_arg(ap, int)) h->flags |= opt; else h->flags &= ~opt; break; @@ -128,7 +129,8 @@ yajl_parse(yajl_handle hand, const unsigned char * jsonText, if (hand->lexer == NULL) { hand->lexer = yajl_lex_alloc(&(hand->alloc), hand->flags & yajl_allow_comments, - !(hand->flags & yajl_dont_validate_strings)); + !(hand->flags & yajl_dont_validate_strings), + hand->flags & yajl_allow_json5); } if (hand->lexer == NULL) { return yajl_status_error; @@ -151,7 +153,8 @@ yajl_complete_parse(yajl_handle hand) if (hand->lexer == NULL) { hand->lexer = yajl_lex_alloc(&(hand->alloc), hand->flags & yajl_allow_comments, - !(hand->flags & yajl_dont_validate_strings)); + !(hand->flags & yajl_dont_validate_strings), + hand->flags & yajl_allow_json5); } return yajl_do_finish(hand); diff --git a/modules/libcom/src/yajl/yajl_lex.c b/modules/libcom/src/yajl/yajl_lex.c index e0cc3b539..b311c2b8a 100644 --- a/modules/libcom/src/yajl/yajl_lex.c +++ b/modules/libcom/src/yajl/yajl_lex.c @@ -87,6 +87,9 @@ struct yajl_lexer_t { /* shall we allow comments? */ unsigned int allowComments; + /* are we parsing JSON5? */ + unsigned int allowJson5; + /* shall we validate utf8 inside strings? */ unsigned int validateUTF8; @@ -102,7 +105,8 @@ struct yajl_lexer_t { yajl_lexer yajl_lex_alloc(yajl_alloc_funcs * alloc, - unsigned int allowComments, unsigned int validateUTF8) + unsigned int allowComments, unsigned int validateUTF8, + unsigned int allowJson5) { yajl_lexer lxr = (yajl_lexer) YA_MALLOC(alloc, sizeof(struct yajl_lexer_t)); if (lxr == NULL) { @@ -113,6 +117,7 @@ yajl_lex_alloc(yajl_alloc_funcs * alloc, lxr->buf = yajl_buf_alloc(alloc); lxr->allowComments = allowComments; lxr->validateUTF8 = validateUTF8; + lxr->allowJson5 = allowJson5; lxr->alloc = alloc; return lxr; } diff --git a/modules/libcom/src/yajl/yajl_lex.h b/modules/libcom/src/yajl/yajl_lex.h index 806ea1de0..7112b8765 100644 --- a/modules/libcom/src/yajl/yajl_lex.h +++ b/modules/libcom/src/yajl/yajl_lex.h @@ -53,7 +53,8 @@ extern "C" { yajl_lexer yajl_lex_alloc(yajl_alloc_funcs * alloc, unsigned int allowComments, - unsigned int validateUTF8); + unsigned int validateUTF8, + unsigned int allowJson5); void yajl_lex_free(yajl_lexer lexer); diff --git a/modules/libcom/src/yajl/yajl_parse.h b/modules/libcom/src/yajl/yajl_parse.h index f7cbbe5a5..c9a1ee216 100644 --- a/modules/libcom/src/yajl/yajl_parse.h +++ b/modules/libcom/src/yajl/yajl_parse.h @@ -155,7 +155,13 @@ extern "C" { * yajl will enter an error state (premature EOF). Setting this * flag suppresses that check and the corresponding error. */ - yajl_allow_partial_values = 0x10 + yajl_allow_partial_values = 0x10, + /** + * The JSON5 standard allows additional formats for numbers, strings + * and object keys which are not permitted in the JSON standard. + * Setting this flag enables JSON5 formats in the lexer and parser. + */ + yajl_allow_json5 = 0x20, } yajl_option; /** Allow the modification of parser options subsequent to handle diff --git a/modules/libcom/test/yajlTestConverter.pl b/modules/libcom/test/yajlTestConverter.pl index c3d2b54b6..31413a6bd 100755 --- a/modules/libcom/test/yajlTestConverter.pl +++ b/modules/libcom/test/yajlTestConverter.pl @@ -22,14 +22,17 @@ my $caseFile = 'yajlTestCases.pm'; my @cases; for my $file (@files) { - $file =~ m|/([afn][cgmp]_)?([^/]*)\.json$|; + $file =~ m|/([afn][5cgmp]_)?([^/]*)\.json$|; my $allow = $1; my $name = $2; next if $name eq ''; my $case = { name => $name }; - if ($allow eq 'ac_') { + if ($allow eq 'a5_') { + $case->{opts} = ['-5']; + } + elsif ($allow eq 'ac_') { $case->{opts} = ['-c']; } elsif ($allow eq 'ag_') { diff --git a/modules/libcom/test/yajl_test.c b/modules/libcom/test/yajl_test.c index cacfdcb5c..178ca6e04 100644 --- a/modules/libcom/test/yajl_test.c +++ b/modules/libcom/test/yajl_test.c @@ -154,6 +154,7 @@ static void usage(const char * progname) "usage: %s [options]\n" "Parse input from stdin as JSON and ouput parsing details " "to stdout\n" + " -5 allow JSON5\n" " -b set the read buffer size\n" " -c allow comments\n" " -g allow *g*arbage after valid JSON text\n" @@ -197,7 +198,9 @@ main(int argc, char ** argv) /* check arguments. We expect exactly one! */ for (i=1;i= argc) usage(argv[0]);