aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/qapi/qmp/json-lexer.h1
-rw-r--r--qobject/json-lexer.c2
-rw-r--r--qobject/json-streamer.c8
-rw-r--r--tests/check-qjson.c8
4 files changed, 15 insertions, 4 deletions
diff --git a/include/qapi/qmp/json-lexer.h b/include/qapi/qmp/json-lexer.h
index afa84cb910..508fc7bdaf 100644
--- a/include/qapi/qmp/json-lexer.h
+++ b/include/qapi/qmp/json-lexer.h
@@ -30,6 +30,7 @@ typedef enum json_token_type {
JSON_INTERP,
JSON_SKIP,
JSON_ERROR,
+ JSON_END_OF_INPUT,
} JSONTokenType;
typedef struct JSONLexer {
diff --git a/qobject/json-lexer.c b/qobject/json-lexer.c
index 01417dca9d..a728c32faa 100644
--- a/qobject/json-lexer.c
+++ b/qobject/json-lexer.c
@@ -347,6 +347,8 @@ void json_lexer_flush(JSONLexer *lexer)
if (lexer->state != lexer->start_state) {
json_lexer_feed_char(lexer, 0, true);
}
+ json_message_process_token(lexer, lexer->token, JSON_END_OF_INPUT,
+ lexer->x, lexer->y);
}
void json_lexer_destroy(JSONLexer *lexer)
diff --git a/qobject/json-streamer.c b/qobject/json-streamer.c
index e372ecc895..674dfe6e85 100644
--- a/qobject/json-streamer.c
+++ b/qobject/json-streamer.c
@@ -60,6 +60,13 @@ void json_message_process_token(JSONLexer *lexer, GString *input,
case JSON_ERROR:
error_setg(&err, "JSON parse error, stray '%s'", input->str);
goto out_emit;
+ case JSON_END_OF_INPUT:
+ if (g_queue_is_empty(parser->tokens)) {
+ return;
+ }
+ json = json_parser_parse(parser->tokens, parser->ap, &err);
+ parser->tokens = NULL;
+ goto out_emit;
default:
break;
}
@@ -137,6 +144,7 @@ void json_message_parser_feed(JSONMessageParser *parser,
void json_message_parser_flush(JSONMessageParser *parser)
{
json_lexer_flush(&parser->lexer);
+ assert(g_queue_is_empty(parser->tokens));
}
void json_message_parser_destroy(JSONMessageParser *parser)
diff --git a/tests/check-qjson.c b/tests/check-qjson.c
index f9438370d9..0ca4b3c823 100644
--- a/tests/check-qjson.c
+++ b/tests/check-qjson.c
@@ -1360,7 +1360,7 @@ static void unterminated_array(void)
{
Error *err = NULL;
QObject *obj = qobject_from_json("[32", &err);
- g_assert(!err); /* BUG */
+ error_free_or_abort(&err);
g_assert(obj == NULL);
}
@@ -1368,7 +1368,7 @@ static void unterminated_array_comma(void)
{
Error *err = NULL;
QObject *obj = qobject_from_json("[32,", &err);
- g_assert(!err); /* BUG */
+ error_free_or_abort(&err);
g_assert(obj == NULL);
}
@@ -1384,7 +1384,7 @@ static void unterminated_dict(void)
{
Error *err = NULL;
QObject *obj = qobject_from_json("{'abc':32", &err);
- g_assert(!err); /* BUG */
+ error_free_or_abort(&err);
g_assert(obj == NULL);
}
@@ -1392,7 +1392,7 @@ static void unterminated_dict_comma(void)
{
Error *err = NULL;
QObject *obj = qobject_from_json("{'abc':32,", &err);
- g_assert(!err); /* BUG */
+ error_free_or_abort(&err);
g_assert(obj == NULL);
}