diff --git a/modules/libcom/src/yajl/yajl_parser.c b/modules/libcom/src/yajl/yajl_parser.c index cb910f79d..795378704 100644 --- a/modules/libcom/src/yajl/yajl_parser.c +++ b/modules/libcom/src/yajl/yajl_parser.c @@ -332,7 +332,8 @@ yajl_do_parse(yajl_handle hand, const unsigned char * jsonText, case yajl_tok_right_bracket: { yajl_state s = yajl_bs_current(hand->stateStack); if (s == yajl_state_array_start || - s == yajl_state_array_need_val) + ((hand->flags & yajl_allow_json5) && + (s == yajl_state_array_need_val))) { if (hand->callbacks && hand->callbacks->yajl_end_array) @@ -404,7 +405,8 @@ yajl_do_parse(yajl_handle hand, const unsigned char * jsonText, case yajl_tok_right_brace: { yajl_state s = yajl_bs_current(hand->stateStack); if (s == yajl_state_map_start || - s == yajl_state_map_need_key) { + ((hand->flags & yajl_allow_json5) && + (s == yajl_state_map_need_key))) { if (hand->callbacks && hand->callbacks->yajl_end_map) { _CC_CHK(hand->callbacks->yajl_end_map(hand->ctx)); } diff --git a/modules/libcom/test/yajlTestCases.pm b/modules/libcom/test/yajlTestCases.pm index 40eaff6e7..fd26d9952 100644 --- a/modules/libcom/test/yajlTestCases.pm +++ b/modules/libcom/test/yajlTestCases.pm @@ -7,6 +7,31 @@ sub cases { my $VAR1 = [ + { + name => "trailing_commas", + opts => [ + -5 + ], + input => [ + "{\"array\":[1,2,],\"map\":{\"a\":1,},}", + "" + ], + gives => [ + "map open '{'", + "key: 'array'", + "array open '['", + "integer: 1", + "integer: 2", + "array close ']'", + "key: 'map'", + "map open '{'", + "key: 'a'", + "integer: 1", + "map close '}'", + "map close '}'", + "memory leaks:\t0" + ] + }, { name => "difficult_json_c_test_case_with_comments", opts => [ @@ -3000,29 +3025,6 @@ sub cases { "memory leaks:\t0" ] }, - { - name => "trailing_commas", - opts => [], - input => [ - "{\"array\":[1,2,],\"map\":{\"a\":1,},}", - "" - ], - gives => [ - "map open '{'", - "key: 'array'", - "array open '['", - "integer: 1", - "integer: 2", - "array close ']'", - "key: 'map'", - "map open '{'", - "key: 'a'", - "integer: 1", - "map close '}'", - "map close '}'", - "memory leaks:\t0" - ] - }, { name => "true", opts => [],