Skip to content

Commit

Permalink
parser: Empty member names are not valid
Browse files Browse the repository at this point in the history
When parsing a JSON object, a member name has to be a valid string, not
an empty one.
  • Loading branch information
ebassi committed Oct 26, 2012
1 parent 32d7c03 commit 028e540
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 13 additions & 0 deletions json-glib/json-parser.c
Expand Up @@ -588,6 +588,19 @@ json_parse_object (JsonParser *parser,
/* member name */
token = json_scanner_get_next_token (scanner);
name = g_strdup (scanner->value.v_string);
if (name == NULL || *name == '\0')
{
JSON_NOTE (PARSER, "Empty object member name");

priv->error_code = JSON_PARSER_ERROR_EMPTY_MEMBER_NAME;

json_object_unref (object);
json_node_free (priv->current_node);
priv->current_node = old_current;

return G_TOKEN_STRING;
}

JSON_NOTE (PARSER, "Object member '%s'", name);

/* a colon separates names from values */
Expand Down
4 changes: 3 additions & 1 deletion json-glib/json-parser.h
Expand Up @@ -54,6 +54,7 @@ typedef struct _JsonParserClass JsonParserClass;
* @JSON_PARSER_ERROR_MISSING_COMMA: expected comma
* @JSON_PARSER_ERROR_MISSING_COLON: expected colon
* @JSON_PARSER_ERROR_INVALID_BAREWORD: invalid bareword
* @JSON_PARSER_ERROR_EMPTY_MEMBER_NAME: empty member name (Since: 0.16)
* @JSON_PARSER_ERROR_UNKNOWN: unknown error
*
* Error enumeration for #JsonParser
Expand All @@ -66,7 +67,8 @@ typedef enum {
JSON_PARSER_ERROR_MISSING_COMMA,
JSON_PARSER_ERROR_MISSING_COLON,
JSON_PARSER_ERROR_INVALID_BAREWORD,

JSON_PARSER_ERROR_EMPTY_MEMBER_NAME,

JSON_PARSER_ERROR_UNKNOWN
} JsonParserError;

Expand Down

0 comments on commit 028e540

Please sign in to comment.