[json-glib] parser: Empty member names are not valid
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [json-glib] parser: Empty member names are not valid
- Date: Fri, 26 Oct 2012 10:14:16 +0000 (UTC)
commit 028e540bc2b78f87e5a1d2f0c36126b7636f2809
Author: Emmanuele Bassi <ebassi gnome org>
Date: Fri Oct 26 10:10:01 2012 +0100
parser: Empty member names are not valid
When parsing a JSON object, a member name has to be a valid string, not
an empty one.
json-glib/json-parser.c | 13 +++++++++++++
json-glib/json-parser.h | 4 +++-
2 files changed, 16 insertions(+), 1 deletions(-)
---
diff --git a/json-glib/json-parser.c b/json-glib/json-parser.c
index d79d21c..4a55763 100644
--- a/json-glib/json-parser.c
+++ b/json-glib/json-parser.c
@@ -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 */
diff --git a/json-glib/json-parser.h b/json-glib/json-parser.h
index 36107f4..fc58b0a 100644
--- a/json-glib/json-parser.h
+++ b/json-glib/json-parser.h
@@ -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
@@ -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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]