From c685f1cdd92866743bb0ae26630844c37aa449a8 Mon Sep 17 00:00:00 2001 From: Thad Megow Date: Tue, 7 Dec 2021 12:35:02 -0500 Subject: [PATCH 01/15] Check for trailing garbage (comma) at the end of objects and arrays, before closing bracket --- json.c | 78 +++++++++++++++++++++++++++++++++++++++++ tests/invalid-0011.json | 3 ++ tests/invalid-0012.json | 3 ++ 3 files changed, 84 insertions(+) create mode 100644 tests/invalid-0011.json create mode 100644 tests/invalid-0012.json diff --git a/json.c b/json.c index 011b5bfa..36c0eaa8 100644 --- a/json.c +++ b/json.c @@ -224,6 +224,8 @@ static int new_value (json_state * state, return 1; } +static int trailing_garbage (const json_char * ptr); + #define whitespace \ case '\n': ++ state.cur_line; state.cur_col = 0; /* FALLTHRU */ \ case ' ': /* FALLTHRU */ case '\t': /* FALLTHRU */ case '\r' @@ -301,6 +303,7 @@ json_value * json_parse_ex (json_settings * settings, for (state.ptr = json ;; ++ state.ptr) { json_char b = (state.ptr == end ? 0 : *state.ptr); + int garbage_check; if (flags & flag_string) { @@ -548,7 +551,16 @@ json_value * json_parse_ex (json_settings * settings, case ']': if (top && top->type == json_array) + { + garbage_check = trailing_garbage(state.ptr); + if (garbage_check) + { + sprintf (error, "Trailing garbage before %d:%d", + state.cur_line, state.cur_col); + goto e_failed; + } flags = (flags & ~ (flag_need_comma | flag_seek_value)) | flag_next; + } else { sprintf (error, "%u:%u: Unexpected `]`", line_and_col); goto e_failed; @@ -740,6 +752,14 @@ json_value * json_parse_ex (json_settings * settings, case '}': + garbage_check = trailing_garbage(state.ptr); + if (garbage_check) + { + sprintf (error, "Trailing garbage before %d:%d", + state.cur_line, state.cur_col); + goto e_failed; + } + flags = (flags & ~ flag_need_comma) | flag_next; break; @@ -1053,3 +1073,61 @@ void json_value_free (json_value * value) settings.mem_free = default_free; json_value_free_ex (&settings, value); } +int trailing_garbage (const json_char * ptr) +{ + json_char marker = *ptr; + do + { + ptr--; + } + while (isspace(*ptr)); + + switch (*ptr) + { + case '}': + case '{': + case ']': + case '[': + case '"': + return 0; + + case 'e': + marker = *(--ptr); + if (marker == 's') + { + if (*(--ptr) == 'l' && *(--ptr) == 'a' && *(--ptr) == 'f') + { + return 0; + } + } + if (marker == 'u') + { + if (*(--ptr) == 'r' && *(--ptr) == 't') + { + return 0; + } + } + + return 1; + + case 'l': + if (*(--ptr) == 'l' && *(--ptr) == 'u' && *(--ptr) == 'n') + { + return 0; + } + else + { + return 1; + } + + default: + if (isdigit(*ptr)) + { + return 0; + } + else + { + return 1; + } + } +} diff --git a/tests/invalid-0011.json b/tests/invalid-0011.json new file mode 100644 index 00000000..56597578 --- /dev/null +++ b/tests/invalid-0011.json @@ -0,0 +1,3 @@ +{ + "a": "b", +} diff --git a/tests/invalid-0012.json b/tests/invalid-0012.json new file mode 100644 index 00000000..994d2fdf --- /dev/null +++ b/tests/invalid-0012.json @@ -0,0 +1,3 @@ +[ + "foo", +] From b819cf4c4364bcc1425898dc4af15fc745d8412d Mon Sep 17 00:00:00 2001 From: Thad Megow Date: Tue, 7 Dec 2021 17:43:00 -0500 Subject: [PATCH 02/15] Improve readability of trailing_garbage function --- json.c | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/json.c b/json.c index 36c0eaa8..2c977bf2 100644 --- a/json.c +++ b/json.c @@ -1073,16 +1073,17 @@ void json_value_free (json_value * value) settings.mem_free = default_free; json_value_free_ex (&settings, value); } + int trailing_garbage (const json_char * ptr) { - json_char marker = *ptr; + json_char * marker = (char *)ptr; do { - ptr--; + marker--; } - while (isspace(*ptr)); + while (isspace(*marker)); - switch (*ptr) + switch (*marker) { case '}': case '{': @@ -1092,36 +1093,30 @@ int trailing_garbage (const json_char * ptr) return 0; case 'e': - marker = *(--ptr); - if (marker == 's') + // Allow true + if (strncmp(marker-3, "true", 4) == 0) { - if (*(--ptr) == 'l' && *(--ptr) == 'a' && *(--ptr) == 'f') - { - return 0; - } + return 0; } - if (marker == 'u') + + // Allow false + if (strncmp(marker-4, "false", 5) == 0) { - if (*(--ptr) == 'r' && *(--ptr) == 't') - { - return 0; - } + return 0; } - return 1; case 'l': - if (*(--ptr) == 'l' && *(--ptr) == 'u' && *(--ptr) == 'n') - { - return 0; - } - else + // Allow null + if (strncmp(marker-3, "null", 4) == 0) { - return 1; + return 0; } + return 1; default: - if (isdigit(*ptr)) + // Allow digits + if (isdigit(*marker)) { return 0; } From 2ab2ddc7d3e20d19e02f315c90a9a52b17b7d2fb Mon Sep 17 00:00:00 2001 From: Thad Megow Date: Tue, 7 Dec 2021 17:43:00 -0500 Subject: [PATCH 03/15] Improve readability of trailing_garbage function --- json.c | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/json.c b/json.c index 36c0eaa8..2c977bf2 100644 --- a/json.c +++ b/json.c @@ -1073,16 +1073,17 @@ void json_value_free (json_value * value) settings.mem_free = default_free; json_value_free_ex (&settings, value); } + int trailing_garbage (const json_char * ptr) { - json_char marker = *ptr; + json_char * marker = (char *)ptr; do { - ptr--; + marker--; } - while (isspace(*ptr)); + while (isspace(*marker)); - switch (*ptr) + switch (*marker) { case '}': case '{': @@ -1092,36 +1093,30 @@ int trailing_garbage (const json_char * ptr) return 0; case 'e': - marker = *(--ptr); - if (marker == 's') + // Allow true + if (strncmp(marker-3, "true", 4) == 0) { - if (*(--ptr) == 'l' && *(--ptr) == 'a' && *(--ptr) == 'f') - { - return 0; - } + return 0; } - if (marker == 'u') + + // Allow false + if (strncmp(marker-4, "false", 5) == 0) { - if (*(--ptr) == 'r' && *(--ptr) == 't') - { - return 0; - } + return 0; } - return 1; case 'l': - if (*(--ptr) == 'l' && *(--ptr) == 'u' && *(--ptr) == 'n') - { - return 0; - } - else + // Allow null + if (strncmp(marker-3, "null", 4) == 0) { - return 1; + return 0; } + return 1; default: - if (isdigit(*ptr)) + // Allow digits + if (isdigit(*marker)) { return 0; } From f11077cb63100b744cd3108112766c1054f39d53 Mon Sep 17 00:00:00 2001 From: Thad Megow Date: Tue, 7 Dec 2021 17:52:23 -0500 Subject: [PATCH 04/15] Add documentation for trailing_garbage func --- json.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/json.c b/json.c index 2c977bf2..3053e3b9 100644 --- a/json.c +++ b/json.c @@ -224,6 +224,9 @@ static int new_value (json_state * state, return 1; } + +// Called when parsing closing brackets of objects and arrays +// Decrements json_char ptr, ignoring whitespace, allowing { } [ ] " true false null static int trailing_garbage (const json_char * ptr); #define whitespace \ From 89a71dc716d6c743470629e5379e628e8e1f28da Mon Sep 17 00:00:00 2001 From: Thad Megow Date: Tue, 7 Dec 2021 18:08:21 -0500 Subject: [PATCH 05/15] Update documentation for trailing_garbage func --- json.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json.c b/json.c index 3053e3b9..485b67a5 100644 --- a/json.c +++ b/json.c @@ -226,7 +226,7 @@ static int new_value (json_state * state, // Called when parsing closing brackets of objects and arrays -// Decrements json_char ptr, ignoring whitespace, allowing { } [ ] " true false null +// Decrements json_char ptr, ignoring whitespace, allowing digits and { } [ ] " true false null static int trailing_garbage (const json_char * ptr); #define whitespace \ From 3c147c03b11c45ee3f80c73df84ab2691e142eb4 Mon Sep 17 00:00:00 2001 From: Thad Megow Date: Wed, 8 Dec 2021 09:35:30 -0500 Subject: [PATCH 06/15] Use classic C comments --- json.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/json.c b/json.c index 485b67a5..0fda5007 100644 --- a/json.c +++ b/json.c @@ -224,9 +224,10 @@ static int new_value (json_state * state, return 1; } - -// Called when parsing closing brackets of objects and arrays -// Decrements json_char ptr, ignoring whitespace, allowing digits and { } [ ] " true false null +/* + * Called when parsing closing brackets of objects and arrays + * Decrements json_char ptr, ignoring whitespace, allowing digits and { } [ ] " true false null + */ static int trailing_garbage (const json_char * ptr); #define whitespace \ From b517d4d6952955a193818a9e0dde914f3f9ad31f Mon Sep 17 00:00:00 2001 From: Thad Megow Date: Wed, 8 Dec 2021 09:38:05 -0500 Subject: [PATCH 07/15] Remove unnecessary var --- json.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/json.c b/json.c index 0fda5007..052a3bdd 100644 --- a/json.c +++ b/json.c @@ -307,7 +307,6 @@ json_value * json_parse_ex (json_settings * settings, for (state.ptr = json ;; ++ state.ptr) { json_char b = (state.ptr == end ? 0 : *state.ptr); - int garbage_check; if (flags & flag_string) { @@ -556,8 +555,7 @@ json_value * json_parse_ex (json_settings * settings, if (top && top->type == json_array) { - garbage_check = trailing_garbage(state.ptr); - if (garbage_check) + if (trailing_garbage(state.ptr)) { sprintf (error, "Trailing garbage before %d:%d", state.cur_line, state.cur_col); @@ -756,8 +754,7 @@ json_value * json_parse_ex (json_settings * settings, case '}': - garbage_check = trailing_garbage(state.ptr); - if (garbage_check) + if (trailing_garbage(state.ptr)) { sprintf (error, "Trailing garbage before %d:%d", state.cur_line, state.cur_col); From fd3e100fecfb4355bdf101a7e1a37feac2261ad7 Mon Sep 17 00:00:00 2001 From: Thad Megow Date: Wed, 8 Dec 2021 09:39:48 -0500 Subject: [PATCH 08/15] Formatting fix --- json.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json.c b/json.c index 052a3bdd..bd01b1a5 100644 --- a/json.c +++ b/json.c @@ -554,7 +554,7 @@ json_value * json_parse_ex (json_settings * settings, case ']': if (top && top->type == json_array) - { + { if (trailing_garbage(state.ptr)) { sprintf (error, "Trailing garbage before %d:%d", From 9d909f04ba8c906c4fc4638f1ede4e934624fa1c Mon Sep 17 00:00:00 2001 From: Thad Megow Date: Wed, 8 Dec 2021 10:11:10 -0500 Subject: [PATCH 09/15] Use classic C comments --- json.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/json.c b/json.c index bd01b1a5..7ead6f65 100644 --- a/json.c +++ b/json.c @@ -1094,13 +1094,13 @@ int trailing_garbage (const json_char * ptr) return 0; case 'e': - // Allow true + /* Allow true */ if (strncmp(marker-3, "true", 4) == 0) { return 0; } - // Allow false + /* Allow false */ if (strncmp(marker-4, "false", 5) == 0) { return 0; @@ -1108,7 +1108,7 @@ int trailing_garbage (const json_char * ptr) return 1; case 'l': - // Allow null + /* Allow null */ if (strncmp(marker-3, "null", 4) == 0) { return 0; @@ -1116,7 +1116,7 @@ int trailing_garbage (const json_char * ptr) return 1; default: - // Allow digits + /* Allow digits */ if (isdigit(*marker)) { return 0; From dcb939c6b329e77874ef7e7526ddfb48ac68cd79 Mon Sep 17 00:00:00 2001 From: Thad Megow Date: Wed, 8 Dec 2021 10:29:58 -0500 Subject: [PATCH 10/15] Fix formatting to use same formatting as the rest of code --- json.c | 109 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 55 insertions(+), 54 deletions(-) diff --git a/json.c b/json.c index 7ead6f65..c0cbf532 100644 --- a/json.c +++ b/json.c @@ -555,16 +555,17 @@ json_value * json_parse_ex (json_settings * settings, if (top && top->type == json_array) { - if (trailing_garbage(state.ptr)) - { - sprintf (error, "Trailing garbage before %d:%d", - state.cur_line, state.cur_col); - goto e_failed; - } + if (trailing_garbage(state.ptr)) + { + sprintf (error, "Trailing garbage before %d:%d", + state.cur_line, state.cur_col); + goto e_failed; + } flags = (flags & ~ (flag_need_comma | flag_seek_value)) | flag_next; } else - { sprintf (error, "%u:%u: Unexpected `]`", line_and_col); + { + sprintf (error, "%u:%u: Unexpected `]`", line_and_col); goto e_failed; } @@ -756,9 +757,9 @@ json_value * json_parse_ex (json_settings * settings, if (trailing_garbage(state.ptr)) { - sprintf (error, "Trailing garbage before %d:%d", - state.cur_line, state.cur_col); - goto e_failed; + sprintf (error, "Trailing garbage before %d:%d", + state.cur_line, state.cur_col); + goto e_failed; } flags = (flags & ~ flag_need_comma) | flag_next; @@ -1077,53 +1078,53 @@ void json_value_free (json_value * value) int trailing_garbage (const json_char * ptr) { - json_char * marker = (char *)ptr; - do - { - marker--; - } - while (isspace(*marker)); - - switch (*marker) - { - case '}': - case '{': - case ']': - case '[': - case '"': + json_char * marker = (char *)ptr; + do + { + marker--; + } + while (isspace(*marker)); + + switch (*marker) + { + case '}': + case '{': + case ']': + case '[': + case '"': + return 0; + + case 'e': + /* Allow true */ + if (strncmp(marker-3, "true", 4) == 0) + { return 0; + } - case 'e': - /* Allow true */ - if (strncmp(marker-3, "true", 4) == 0) - { - return 0; - } + /* Allow false */ + if (strncmp(marker-4, "false", 5) == 0) + { + return 0; + } + return 1; - /* Allow false */ - if (strncmp(marker-4, "false", 5) == 0) - { - return 0; - } - return 1; + case 'l': + /* Allow null */ + if (strncmp(marker-3, "null", 4) == 0) + { + return 0; + } + return 1; - case 'l': - /* Allow null */ - if (strncmp(marker-3, "null", 4) == 0) - { - return 0; - } + default: + /* Allow digits */ + if (isdigit(*marker)) + { + return 0; + } + else + { return 1; - - default: - /* Allow digits */ - if (isdigit(*marker)) - { - return 0; - } - else - { - return 1; - } - } + } + } } From 2cdb3209241a69bffc7055911594e1760d31aff4 Mon Sep 17 00:00:00 2001 From: Thad Megow Date: Thu, 9 Dec 2021 10:37:26 -0500 Subject: [PATCH 11/15] Update number of invalid tests from 10->12 --- tests/test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test.c b/tests/test.c index 9d2c4fba..e13b1a98 100644 --- a/tests/test.c +++ b/tests/test.c @@ -227,7 +227,7 @@ int main(void) JSON_COMPARE_STRING(1, "\\ud841\\udf31", "𠜱"); /* TODO: this should actually succeed after PR #58 is merged */ if(0 != json_verify( "valid-%04u.json", 13, 0, 0)){ exit_code = EXIT_FAILURE; } - if(0 != json_verify( "invalid-%04u.json", 10, 0, 1)){ exit_code = EXIT_FAILURE; } + if(0 != json_verify( "invalid-%04u.json", 12, 0, 1)){ exit_code = EXIT_FAILURE; } if(0 != json_verify( "ext-valid-%04u.json", 3, 1, 0)){ exit_code = EXIT_FAILURE; } if(0 != json_verify("ext-invalid-%04u.json", 2, 1, 1)){ exit_code = EXIT_FAILURE; } From eab95827f17f64ce1a83a48f66fb9dec30be8cc3 Mon Sep 17 00:00:00 2001 From: Thad Megow Date: Sun, 19 Dec 2021 13:27:12 -0500 Subject: [PATCH 12/15] Make loading of conditional code branches used for linting be dependent upon a compile-time option. Enable runtime option for enabling linting when compile-time option is set. Make compile-time option accept values of unset, 1, or 2 - with 1 requiring the runtime option to be included for linting to run and with 2 loading and running the linting code without requiring the runtime option --- README.md | 4 ++++ examples/test_json.c | 8 ++++++++ json.c | 44 ++++++++++++++++++++++++++++++-------------- json.h | 1 + 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 5ac0a3a9..09cc7277 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,10 @@ settings |= json_enable_comments; ``` Enables C-style `// line` and `/* block */` comments. ```c +settings |= json_enable_linting; +``` +Enables strict ECMA-404 JSON parsing +```c size_t value_extra ``` The amount of space (if any) to allocate at the end of each `json_value`, in diff --git a/examples/test_json.c b/examples/test_json.c index 85fdf783..007b59c5 100644 --- a/examples/test_json.c +++ b/examples/test_json.c @@ -168,6 +168,14 @@ int main(int argc, char** argv) value = json_parse(json,file_size); + /* + * Use json_parse_ex to enable runtime options + */ + /* json_settings settings = { 0 }; */ + /* settings.settings |= json_enable_comments; */ + /* settings.settings |= json_enable_linting; */ + /* value = json_parse_ex(&settings, json, file_size, 0); */ + if (value == NULL) { fprintf(stderr, "Unable to parse data\n"); free(file_contents); diff --git a/json.c b/json.c index c0cbf532..578d2d3b 100644 --- a/json.c +++ b/json.c @@ -69,6 +69,18 @@ typedef unsigned int json_uchar; const struct _json_value json_value_none; +#if defined JSON_LINTING && JSON_LINTING == 1 +int compile_option_linting = 0; +#elif defined JSON_LINTING && JSON_LINTING == 2 +int compile_option_linting = 1; +#endif + +/* + * Called when parsing closing brackets of objects and arrays + * Decrements json_char ptr, ignoring whitespace, allowing digits and { } [ ] " true false null + */ +static int trailing_garbage (const json_char * ptr); + static unsigned char hex_value (json_char c) { if (isdigit((unsigned char)c)) @@ -224,12 +236,6 @@ static int new_value (json_state * state, return 1; } -/* - * Called when parsing closing brackets of objects and arrays - * Decrements json_char ptr, ignoring whitespace, allowing digits and { } [ ] " true false null - */ -static int trailing_garbage (const json_char * ptr); - #define whitespace \ case '\n': ++ state.cur_line; state.cur_col = 0; /* FALLTHRU */ \ case ' ': /* FALLTHRU */ case '\t': /* FALLTHRU */ case '\r' @@ -555,12 +561,17 @@ json_value * json_parse_ex (json_settings * settings, if (top && top->type == json_array) { - if (trailing_garbage(state.ptr)) + #if defined JSON_LINTING && (JSON_LINTING == 1 || JSON_LINTING == 2) + if (state.settings.settings & json_enable_linting || compile_option_linting == 1) { - sprintf (error, "Trailing garbage before %d:%d", - state.cur_line, state.cur_col); - goto e_failed; + if (trailing_garbage(state.ptr)) + { + sprintf (error, "Trailing garbage before %d:%d", + state.cur_line, state.cur_col); + goto e_failed; + } } + #endif flags = (flags & ~ (flag_need_comma | flag_seek_value)) | flag_next; } else @@ -755,12 +766,17 @@ json_value * json_parse_ex (json_settings * settings, case '}': - if (trailing_garbage(state.ptr)) + #if defined JSON_LINTING && (JSON_LINTING == 1 || JSON_LINTING == 2) + if (state.settings.settings & json_enable_linting || compile_option_linting == 1) { - sprintf (error, "Trailing garbage before %d:%d", - state.cur_line, state.cur_col); - goto e_failed; + if (trailing_garbage(state.ptr)) + { + sprintf (error, "Trailing garbage before %d:%d", + state.cur_line, state.cur_col); + goto e_failed; + } } + #endif flags = (flags & ~ flag_need_comma) | flag_next; break; diff --git a/json.h b/json.h index 1f643161..81486c20 100644 --- a/json.h +++ b/json.h @@ -80,6 +80,7 @@ typedef struct } json_settings; #define json_enable_comments 0x01 +#define json_enable_linting 0x02 typedef enum { From 578fa7de3a7eef91be03b25432781adc39441663 Mon Sep 17 00:00:00 2001 From: Thad Megow Date: Sun, 19 Dec 2021 13:50:54 -0500 Subject: [PATCH 13/15] Add compile-time option documentation for JSON_LINTING --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 09cc7277..56054c65 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,16 @@ Example usage: * `"-Djson_int_t=long long"` * `-Djson_int_t=__int128` +### `JSON_LINTING` +Loads code branches used for strict ECMA-404 JSON parsing. + +Setting JSON_LINTING to 1 additionally requires the use of the runtime option (json_enable_comments) to perform linting. +Setting JSON_LINTING to 2 performs linting without requiring the runtime option. + +Example usage: +* `-DJSON_LINTING=1` +* `-DJSON_LINTING=2` + Runtime Options --------------- From d8e78f286a19a18f4d1e53b9bc53f04ab525b93e Mon Sep 17 00:00:00 2001 From: Thad Megow Date: Sun, 19 Dec 2021 14:21:41 -0500 Subject: [PATCH 14/15] Enable JSON_LINTING compile time option during tests and enable json_enable_linting runtime option when extensions == 1 in json_verify --- configure | 2 +- configure.ac | 2 +- tests/test.c | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/configure b/configure index cc37789b..ecf7cd9b 100755 --- a/configure +++ b/configure @@ -2655,7 +2655,7 @@ else fi if test "x$enable_value_pos" = xyes; then - CFLAGS="$CFLAGS -DJSON_TRACK_SOURCE" + CFLAGS="$CFLAGS -DJSON_TRACK_SOURCE -DJSON_LINTING=1" fi VERSION_MAJOR=$VERSION_MAJOR diff --git a/configure.ac b/configure.ac index d5d4488c..ed968666 100644 --- a/configure.ac +++ b/configure.ac @@ -26,7 +26,7 @@ AC_ARG_ENABLE([track-source], [enable_value_pos=no] ) if test "x$enable_value_pos" = xyes; then - CFLAGS="$CFLAGS -DJSON_TRACK_SOURCE" + CFLAGS="$CFLAGS -DJSON_TRACK_SOURCE -DJSON_LINTING=1" fi AC_SUBST(VERSION_MAJOR, $VERSION_MAJOR) diff --git a/tests/test.c b/tests/test.c index e13b1a98..42b12633 100644 --- a/tests/test.c +++ b/tests/test.c @@ -136,7 +136,8 @@ static int json_verify(const char * filename_format, unsigned highest_file_num, if(extensions == 1) { - settings.settings = json_enable_comments; + settings.settings |= json_enable_comments; + settings.settings |= json_enable_linting; } for(test_num = 0; ; ++test_num) From 6d63a372cdd386d89212eaa950e6d9bccfdfad5b Mon Sep 17 00:00:00 2001 From: Thad Megow Date: Sun, 19 Dec 2021 14:42:30 -0500 Subject: [PATCH 15/15] Fix previous attempt to enable JSON_LINTING during tests. Create --enable-linting configure option for autoconf. --- .github/workflows/main.yml | 4 ++-- configure | 2 +- configure.ac | 12 +++++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 614352fd..d921251b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -55,7 +55,7 @@ jobs: - name: Build and run tests run: | - c89 -ansi -Wall -Wpedantic -Werror -pedantic -pedantic-errors -D_ANSI_SOURCE -DJSON_TRACK_SOURCE -I. json.c tests/test.c -lm -o json-test + c89 -ansi -Wall -Wpedantic -Werror -pedantic -pedantic-errors -D_ANSI_SOURCE -DJSON_TRACK_SOURCE -DJSON_LINTING=1 -I. json.c tests/test.c -lm -o json-test cd tests ../json-test @@ -103,7 +103,7 @@ jobs: run: cl /permissive- /Zc:preprocessor /Zc:throwingNew /volatile:iso /utf-8 /std:c++latest /Zc:__cplusplus /Wall /DJSON_TRACK_SOURCE /LD /Tp json.c - name: Build test executable - run: cl /permissive- /Zc:preprocessor /Zc:throwingNew /volatile:iso /utf-8 /std:c++latest /Zc:__cplusplus /Wall /DJSON_TRACK_SOURCE /I . /MT /Tp json.c /Tp tests\test.c /Fetests\json-test.exe + run: cl /permissive- /Zc:preprocessor /Zc:throwingNew /volatile:iso /utf-8 /std:c++latest /Zc:__cplusplus /Wall /DJSON_TRACK_SOURCE /DJSON_LINTING=1 /I . /MT /Tp json.c /Tp tests\test.c /Fetests\json-test.exe - name: Run tests if: matrix.arch != 'amd64_arm' && matrix.arch != 'amd64_arm64' diff --git a/configure b/configure index ecf7cd9b..cc37789b 100755 --- a/configure +++ b/configure @@ -2655,7 +2655,7 @@ else fi if test "x$enable_value_pos" = xyes; then - CFLAGS="$CFLAGS -DJSON_TRACK_SOURCE -DJSON_LINTING=1" + CFLAGS="$CFLAGS -DJSON_TRACK_SOURCE" fi VERSION_MAJOR=$VERSION_MAJOR diff --git a/configure.ac b/configure.ac index ed968666..68c4645a 100644 --- a/configure.ac +++ b/configure.ac @@ -26,7 +26,17 @@ AC_ARG_ENABLE([track-source], [enable_value_pos=no] ) if test "x$enable_value_pos" = xyes; then - CFLAGS="$CFLAGS -DJSON_TRACK_SOURCE -DJSON_LINTING=1" + CFLAGS="$CFLAGS -DJSON_TRACK_SOURCE" +fi + +AC_ARG_ENABLE([enable-linting], + [AS_HELP_STRING([--enable-linting], + [ Enables strict ECMA-404 JSON parsing. @<:@default=disabled@:>@])], + [enable_linting="$enableval"], + [enable_linting=no] +) +if test "x$enable_linting" = xyes; then + CFLAGS="$CFLAGS -DJSON_LINTING=1" fi AC_SUBST(VERSION_MAJOR, $VERSION_MAJOR)