diff options
author | Alexey Botchkov <holyfoot@askmonty.org> | 2017-09-12 11:20:30 +0400 |
---|---|---|
committer | Alexey Botchkov <holyfoot@askmonty.org> | 2017-09-12 11:20:30 +0400 |
commit | 6352ec2184dc8e5744aed3f718fc635edb4b511f (patch) | |
tree | 384d91f8b9745139274528db590fc01538726759 | |
parent | 31774f0ede81d77d889061324930d3d0066c653a (diff) | |
download | mariadb-git-6352ec2184dc8e5744aed3f718fc635edb4b511f.tar.gz |
MDEV-12982 JSON_EXTRACT returns data for invalid JSON.
Let's check the validity to the end of the JSON.
-rw-r--r-- | mysql-test/r/func_json.result | 5 | ||||
-rw-r--r-- | mysql-test/t/func_json.test | 5 | ||||
-rw-r--r-- | sql/item_jsonfunc.cc | 4 |
3 files changed, 14 insertions, 0 deletions
diff --git a/mysql-test/r/func_json.result b/mysql-test/r/func_json.result index aa8a2850a58..f89c5f1c71b 100644 --- a/mysql-test/r/func_json.result +++ b/mysql-test/r/func_json.result @@ -669,3 +669,8 @@ JSON_EXTRACT('{\"asdf\":true}', "$.\"asdf\"") = 1 select JSON_EXTRACT('{\"input1\":\"\\u00f6\"}', '$.\"input1\"'); JSON_EXTRACT('{\"input1\":\"\\u00f6\"}', '$.\"input1\"') "\u00f6" +select JSON_EXTRACT('{"foo": "bar" foobar foo invalid ', '$.foo'); +JSON_EXTRACT('{"foo": "bar" foobar foo invalid ', '$.foo') +NULL +Warnings: +Warning 4038 Syntax error in JSON text in argument 1 to function 'json_extract' at position 15 diff --git a/mysql-test/t/func_json.test b/mysql-test/t/func_json.test index 3bbda0de409..eba492b72e8 100644 --- a/mysql-test/t/func_json.test +++ b/mysql-test/t/func_json.test @@ -317,3 +317,8 @@ select JSON_EXTRACT('{\"asdf\":true}', "$.\"asdf\"") = false; select JSON_EXTRACT('{\"asdf\":true}', "$.\"asdf\"") = 1; select JSON_EXTRACT('{\"input1\":\"\\u00f6\"}', '$.\"input1\"'); +# +# MDEV-129892 JSON_EXTRACT returns data for invalid JSON +# +select JSON_EXTRACT('{"foo": "bar" foobar foo invalid ', '$.foo'); + diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc index c2a9ca28c99..c30ce45bfb2 100644 --- a/sql/item_jsonfunc.cc +++ b/sql/item_jsonfunc.cc @@ -821,7 +821,11 @@ String *Item_func_json_extract::read_json(String *str, not_first_value= 1; if (!possible_multiple_values) + { + /* Loop to the end of the JSON just to make sure it's valid. */ + while (json_get_path_next(&je, &p) == 0) {} break; + } } if (je.s.error) |