From 00ac15cec5b6b5bfc542830d89e10b37403b5af9 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Tue, 7 Jul 2020 00:36:11 -0500 Subject: [PATCH] Turning on JSON5 also enables comments Includes the simple test case. --- modules/libcom/src/yajl/yajl.c | 3 ++- modules/libcom/test/yajlTestCases.pm | 31 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/modules/libcom/src/yajl/yajl.c b/modules/libcom/src/yajl/yajl.c index 87795b173..c21e163dd 100644 --- a/modules/libcom/src/yajl/yajl.c +++ b/modules/libcom/src/yajl/yajl.c @@ -90,12 +90,13 @@ yajl_config(yajl_handle h, int option, ...) va_start(ap, option); switch(opt) { + case yajl_allow_json5: + opt |= yajl_allow_comments; /* JSON5 allows comments */ case yajl_allow_comments: case yajl_dont_validate_strings: 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; diff --git a/modules/libcom/test/yajlTestCases.pm b/modules/libcom/test/yajlTestCases.pm index 9a651c8cd..9b5530338 100644 --- a/modules/libcom/test/yajlTestCases.pm +++ b/modules/libcom/test/yajlTestCases.pm @@ -54,6 +54,37 @@ sub cases { "memory leaks:\t0" ] }, + { + name => "simple_with_comments", + opts => [ + -5 + ], + input => [ + "{", + " \"this\": \"is\", // ignore this", + " \"really\": \"simple\",", + " /* ignore", + "this", + "too * / ", + "** //", + "(/", + "******/", + " \"json\": \"right?\"", + "}", + "" + ], + gives => [ + "map open '{'", + "key: 'this'", + "string: 'is'", + "key: 'really'", + "string: 'simple'", + "key: 'json'", + "string: 'right?'", + "map close '}'", + "memory leaks:\t0" + ] + }, { name => "trailing_commas", opts => [