summaryrefslogtreecommitdiff
path: root/json_tokener.c
diff options
context:
space:
mode:
authorEric Haszlakiewicz <erh+git@nimenees.com>2013-03-31 20:05:36 -0500
committerEric Haszlakiewicz <erh+git@nimenees.com>2013-03-31 20:05:36 -0500
commite8161a11bbc2d34c459c5ae9b91750e49a8963e3 (patch)
treeed73a60c84ff96abf07d6baf1d2ec0910ff2a8dc /json_tokener.c
parent889400d946e3e6efa80b336c6c48c63de91d26bb (diff)
downloadjson-c-e8161a11bbc2d34c459c5ae9b91750e49a8963e3.tar.gz
Issue #15: add a way to set a JSON_TOKENER_STRICT flag to forbid commas at the end of arrays and objects.
Diffstat (limited to 'json_tokener.c')
-rw-r--r--json_tokener.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/json_tokener.c b/json_tokener.c
index 6d50bc2..b2b47f9 100644
--- a/json_tokener.c
+++ b/json_tokener.c
@@ -624,8 +624,15 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok,
}
break;
+ case json_tokener_state_array_after_sep:
case json_tokener_state_array:
if(c == ']') {
+ if (state == json_tokener_state_array_after_sep &&
+ (tok->flags & JSON_TOKENER_STRICT))
+ {
+ tok->err = json_tokener_error_parse_unexpected;
+ goto out;
+ }
saved_state = json_tokener_state_finish;
state = json_tokener_state_eatws;
} else {
@@ -651,7 +658,7 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok,
saved_state = json_tokener_state_finish;
state = json_tokener_state_eatws;
} else if(c == ',') {
- saved_state = json_tokener_state_array;
+ saved_state = json_tokener_state_array_after_sep;
state = json_tokener_state_eatws;
} else {
tok->err = json_tokener_error_parse_array;
@@ -660,7 +667,14 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok,
break;
case json_tokener_state_object_field_start:
+ case json_tokener_state_object_field_start_after_sep:
if(c == '}') {
+ if (state == json_tokener_state_object_field_start_after_sep &&
+ (tok->flags & JSON_TOKENER_STRICT))
+ {
+ tok->err = json_tokener_error_parse_unexpected;
+ goto out;
+ }
saved_state = json_tokener_state_finish;
state = json_tokener_state_eatws;
} else if (c == '"' || c == '\'') {
@@ -731,7 +745,7 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok,
saved_state = json_tokener_state_finish;
state = json_tokener_state_eatws;
} else if(c == ',') {
- saved_state = json_tokener_state_object_field_start;
+ saved_state = json_tokener_state_object_field_start_after_sep;
state = json_tokener_state_eatws;
} else {
tok->err = json_tokener_error_parse_object_value_sep;
@@ -771,3 +785,8 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok,
json_tokener_errors[tok->err], tok->char_offset);
return NULL;
}
+
+void json_tokener_set_flags(struct json_tokener *tok, int flags)
+{
+ tok->flags = flags;
+}