json: Improve strictness of the JSON parser

Backport of the upstream JSON-GLib commit that improved the strictness
of JsonParser.

The original upstream commit is:

  29881f03468db08bfb404cfcd5b61b4cdc419a87
This commit is contained in:
Emmanuele Bassi 2010-03-07 20:54:33 +00:00
parent 7c6567704d
commit 9ad1197cb2

View File

@ -358,13 +358,6 @@ json_parse_array (JsonParser *parser,
JsonNode *node = NULL;
gboolean negative = FALSE;
if (token == G_TOKEN_COMMA)
{
/* swallow the comma */
token = g_scanner_get_next_token (scanner);
continue;
}
/* nested object */
if (token == G_TOKEN_LEFT_CURLY)
{
@ -396,9 +389,20 @@ json_parse_array (JsonParser *parser,
if (token == G_TOKEN_RIGHT_BRACE)
break;
if (token == G_TOKEN_COMMA)
{
token = g_scanner_get_next_token (scanner);
if (token == G_TOKEN_RIGHT_BRACE)
return G_TOKEN_SYMBOL;
continue;
}
json_array_unref (array);
return G_TOKEN_RIGHT_BRACE;
}
/* nested array */
if (token == G_TOKEN_LEFT_BRACE)
{
@ -430,9 +434,20 @@ json_parse_array (JsonParser *parser,
if (token == G_TOKEN_RIGHT_BRACE)
break;
if (token == G_TOKEN_COMMA)
{
token = g_scanner_get_next_token (scanner);
if (token == G_TOKEN_RIGHT_BRACE)
return G_TOKEN_SYMBOL;
continue;
}
json_array_unref (array);
return G_TOKEN_RIGHT_BRACE;
}
if (token == '-')
{
guint next_token = g_scanner_peek_next_token (scanner);
@ -497,6 +512,21 @@ json_parse_array (JsonParser *parser,
}
token = g_scanner_get_next_token (scanner);
if (token == G_TOKEN_RIGHT_BRACE)
break;
if (token == G_TOKEN_COMMA)
{
token = g_scanner_get_next_token (scanner);
if (token == G_TOKEN_RIGHT_BRACE)
return G_TOKEN_SYMBOL;
continue;
}
json_array_unref (array);
return G_TOKEN_RIGHT_BRACE;
}
json_node_take_array (priv->current_node, array);
@ -534,13 +564,6 @@ json_parse_object (JsonParser *parser,
gchar *name = NULL;
gboolean negative = FALSE;
if (token == G_TOKEN_COMMA)
{
/* swallow the comma */
token = g_scanner_get_next_token (scanner);
continue;
}
if (token == G_TOKEN_STRING)
{
name = g_strdup (scanner->value.v_string);
@ -603,9 +626,20 @@ json_parse_object (JsonParser *parser,
if (token == G_TOKEN_RIGHT_CURLY)
break;
if (token == G_TOKEN_COMMA)
{
token = g_scanner_get_next_token (scanner);
if (token == G_TOKEN_RIGHT_CURLY)
return G_TOKEN_SYMBOL;
continue;
}
json_object_unref (object);
return G_TOKEN_RIGHT_CURLY;
}
if (token == G_TOKEN_LEFT_BRACE)
{
JsonNode *old_node = priv->current_node;
@ -636,12 +670,23 @@ json_parse_object (JsonParser *parser,
g_free (name);
token = g_scanner_get_next_token (scanner);
if (token == G_TOKEN_RIGHT_BRACE)
if (token == G_TOKEN_RIGHT_CURLY)
break;
if (token == G_TOKEN_COMMA)
{
token = g_scanner_get_next_token (scanner);
if (token == G_TOKEN_RIGHT_CURLY)
return G_TOKEN_SYMBOL;
continue;
}
json_object_unref (object);
return G_TOKEN_RIGHT_CURLY;
}
if (token == '-')
{
guint next_token = g_scanner_peek_next_token (scanner);
@ -707,6 +752,21 @@ json_parse_object (JsonParser *parser,
g_free (name);
token = g_scanner_get_next_token (scanner);
if (token == G_TOKEN_RIGHT_CURLY)
break;
if (token == G_TOKEN_COMMA)
{
token = g_scanner_get_next_token (scanner);
if (token == G_TOKEN_RIGHT_CURLY)
return G_TOKEN_SYMBOL;
continue;
}
json_object_unref (object);
return G_TOKEN_RIGHT_CURLY;
}
json_node_take_object (priv->current_node, object);