From a1490d9b6a3a21774d68f085f805d5f7a68b305e Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Thu, 25 Feb 2016 09:42:54 +0000 Subject: parser: Detect missing commas in arrays Just like we detect trailing commas, we should also detect missing ones to avoid parsing invalid JSON successfully. --- json-glib/json-parser.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'json-glib/json-parser.c') diff --git a/json-glib/json-parser.c b/json-glib/json-parser.c index ee4e765..812f038 100644 --- a/json-glib/json-parser.c +++ b/json-glib/json-parser.c @@ -488,12 +488,25 @@ json_parse_array (JsonParser *parser, next_token = json_scanner_peek_next_token (scanner); + /* look for missing commas */ + if (next_token != G_TOKEN_COMMA && next_token != G_TOKEN_RIGHT_BRACE) + { + priv->error_code = JSON_PARSER_ERROR_MISSING_COMMA; + + json_array_unref (array); + json_node_free (priv->current_node); + json_node_free (element); + priv->current_node = old_current; + + return G_TOKEN_COMMA; + } + + /* look for trailing commas */ if (next_token == G_TOKEN_COMMA) { token = json_scanner_get_next_token (scanner); next_token = json_scanner_peek_next_token (scanner); - /* look for trailing commas */ if (next_token == G_TOKEN_RIGHT_BRACE) { priv->error_code = JSON_PARSER_ERROR_TRAILING_COMMA; -- cgit v1.2.1