diff --git a/mysql-test/main/json_normalize.result b/mysql-test/main/json_normalize.result index cd5b6d3d2bf..ee92e047683 100644 --- a/mysql-test/main/json_normalize.result +++ b/mysql-test/main/json_normalize.result @@ -45,6 +45,21 @@ json_normalize('{ "invalid": "no_close"') NULL Warnings: Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_normalize' +select json_normalize(''); +json_normalize('') +NULL +Warnings: +Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_normalize' +select json_normalize(' '); +json_normalize(' ') +NULL +Warnings: +Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_normalize' +select json_normalize('123 garbage'); +json_normalize('123 garbage') +NULL +Warnings: +Warning 4038 Syntax error in JSON text in argument 1 to function 'json_normalize' at position 5 drop table t1; drop view v1; create table t1 (text varchar(200) character set 'latin1'); diff --git a/mysql-test/main/json_normalize.test b/mysql-test/main/json_normalize.test index a1c0b12026d..d4f27efd2c8 100644 --- a/mysql-test/main/json_normalize.test +++ b/mysql-test/main/json_normalize.test @@ -25,6 +25,9 @@ order by json; select json_normalize(NULL); select json_normalize('{ "invalid": "no_close"'); +select json_normalize(''); +select json_normalize(' '); +select json_normalize('123 garbage'); drop table t1; drop view v1; diff --git a/strings/json_normalize.c b/strings/json_normalize.c index 5243bd3c706..7557f18fd4d 100644 --- a/strings/json_normalize.c +++ b/strings/json_normalize.c @@ -829,7 +829,7 @@ json_norm_parse(struct json_norm_value *root, json_engine_t *je) json_norm_parse_end: dynstr_free(&key); - return err; + return err || je->s.error; } @@ -860,6 +860,10 @@ json_norm_build(json_engine_t *je, struct json_norm_value *root, if (err) return err; } + else + { + while(json_scan_next(je) == 0) /*no-op*/; + } return err; } @@ -908,14 +912,9 @@ json_normalize_engine(json_engine_t *je, DYNAMIC_STRING *result, in_size= strlen(s_utf8); } - - if (!json_valid_engine(je, in, in_size, &my_charset_utf8mb4_bin)) - { - err= 1; - goto json_normalize_end; - } - err= json_norm_build(je, &root, in, in_size, &my_charset_utf8mb4_bin); + if (root.type == JSON_VALUE_UNINITIALIZED || je->s.error) + err= 1; if (err) goto json_normalize_end;