1.4.0: Accepting trailing commas in objects and arrays

Issue #178
This commit is contained in:
Krzysztof Gabis 2022-03-06 21:27:20 +01:00
parent 4158fdbea7
commit a34e725282
6 changed files with 20 additions and 12 deletions

View File

@ -3,7 +3,7 @@ project(parson C)
include (GNUInstallDirs) include (GNUInstallDirs)
set(PARSON_VERSION 1.3.1) set(PARSON_VERSION 1.4.0)
add_library(parson parson.c) add_library(parson parson.c)
target_include_directories(parson PUBLIC $<INSTALL_INTERFACE:include>) target_include_directories(parson PUBLIC $<INSTALL_INTERFACE:include>)

View File

@ -1,6 +1,6 @@
{ {
"name": "parson", "name": "parson",
"version": "1.3.1", "version": "1.4.0",
"repo": "kgabis/parson", "repo": "kgabis/parson",
"description": "Small json parser and reader", "description": "Small json parser and reader",
"keywords": [ "json", "parser" ], "keywords": [ "json", "parser" ],

View File

@ -1,7 +1,7 @@
/* /*
SPDX-License-Identifier: MIT SPDX-License-Identifier: MIT
Parson 1.3.1 (https://github.com/kgabis/parson) Parson 1.4.0 (https://github.com/kgabis/parson)
Copyright (c) 2012 - 2022 Krzysztof Gabis Copyright (c) 2012 - 2022 Krzysztof Gabis
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
@ -31,8 +31,8 @@
#include "parson.h" #include "parson.h"
#define PARSON_IMPL_VERSION_MAJOR 1 #define PARSON_IMPL_VERSION_MAJOR 1
#define PARSON_IMPL_VERSION_MINOR 3 #define PARSON_IMPL_VERSION_MINOR 4
#define PARSON_IMPL_VERSION_PATCH 1 #define PARSON_IMPL_VERSION_PATCH 0
#if (PARSON_VERSION_MAJOR != PARSON_IMPL_VERSION_MAJOR)\ #if (PARSON_VERSION_MAJOR != PARSON_IMPL_VERSION_MAJOR)\
|| (PARSON_VERSION_MINOR != PARSON_IMPL_VERSION_MINOR)\ || (PARSON_VERSION_MINOR != PARSON_IMPL_VERSION_MINOR)\
@ -980,6 +980,9 @@ static JSON_Value * parse_object_value(const char **string, size_t nesting) {
} }
SKIP_CHAR(string); SKIP_CHAR(string);
SKIP_WHITESPACES(string); SKIP_WHITESPACES(string);
if (**string == '}') {
break;
}
} }
SKIP_WHITESPACES(string); SKIP_WHITESPACES(string);
if (**string != '}') { if (**string != '}') {
@ -1025,6 +1028,9 @@ static JSON_Value * parse_array_value(const char **string, size_t nesting) {
} }
SKIP_CHAR(string); SKIP_CHAR(string);
SKIP_WHITESPACES(string); SKIP_WHITESPACES(string);
if (**string == ']') {
break;
}
} }
SKIP_WHITESPACES(string); SKIP_WHITESPACES(string);
if (**string != ']' || /* Trim array after parsing is over */ if (**string != ']' || /* Trim array after parsing is over */

View File

@ -1,7 +1,7 @@
/* /*
SPDX-License-Identifier: MIT SPDX-License-Identifier: MIT
Parson 1.3.1 (https://github.com/kgabis/parson) Parson 1.4.0 (https://github.com/kgabis/parson)
Copyright (c) 2012 - 2022 Krzysztof Gabis Copyright (c) 2012 - 2022 Krzysztof Gabis
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
@ -35,10 +35,10 @@ extern "C"
#endif #endif
#define PARSON_VERSION_MAJOR 1 #define PARSON_VERSION_MAJOR 1
#define PARSON_VERSION_MINOR 3 #define PARSON_VERSION_MINOR 4
#define PARSON_VERSION_PATCH 1 #define PARSON_VERSION_PATCH 0
#define PARSON_VERSION_STRING "1.3.1" #define PARSON_VERSION_STRING "1.4.0"
#include <stddef.h> /* size_t */ #include <stddef.h> /* size_t */

View File

@ -307,6 +307,8 @@ void test_suite_3(void) {
TEST(json_parse_string("false") != NULL); TEST(json_parse_string("false") != NULL);
TEST(json_parse_string("\"string\"") != NULL); TEST(json_parse_string("\"string\"") != NULL);
TEST(json_parse_string("123") != NULL); TEST(json_parse_string("123") != NULL);
TEST(json_parse_string("[\"lorem\",]") != NULL);
TEST(json_parse_string("{\"lorem\":\"ipsum\",}") != NULL);
/* Test UTF-16 parsing */ /* Test UTF-16 parsing */
TEST(STREQ(json_string(json_parse_string("\"\\u0024x\"")), "$x")); TEST(STREQ(json_string(json_parse_string("\"\\u0024x\"")), "$x"));
@ -318,9 +320,9 @@ void test_suite_3(void) {
g_malloc_count = 0; g_malloc_count = 0;
TEST(json_parse_string(NULL) == NULL); TEST(json_parse_string(NULL) == NULL);
TEST(json_parse_string("") == NULL); /* empty string */ TEST(json_parse_string("") == NULL); /* empty string */
TEST(json_parse_string("[\"lorem\",]") == NULL);
TEST(json_parse_string("{\"lorem\":\"ipsum\",}") == NULL);
TEST(json_parse_string("{lorem:ipsum}") == NULL); TEST(json_parse_string("{lorem:ipsum}") == NULL);
TEST(json_parse_string("{\"lorem\":\"ipsum\",]") == NULL);
TEST(json_parse_string("{\"lorem\":\"ipsum\",,}") == NULL);
TEST(json_parse_string("[,]") == NULL); TEST(json_parse_string("[,]") == NULL);
TEST(json_parse_string("[,") == NULL); TEST(json_parse_string("[,") == NULL);
TEST(json_parse_string("[") == NULL); TEST(json_parse_string("[") == NULL);

View File

@ -31,5 +31,5 @@
"url" : "https:\/\/www.example.com\/search?q=12345", "url" : "https:\/\/www.example.com\/search?q=12345",
"escaped chars" : "\" \\ \/", "escaped chars" : "\" \\ \/",
"empty object" : {}, "empty object" : {},
"empty array" : [] "empty array" : [],
} }