summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Botchkov <holyfoot@askmonty.org>2017-09-12 11:20:30 +0400
committerAlexey Botchkov <holyfoot@askmonty.org>2017-09-12 11:20:30 +0400
commit6352ec2184dc8e5744aed3f718fc635edb4b511f (patch)
tree384d91f8b9745139274528db590fc01538726759
parent31774f0ede81d77d889061324930d3d0066c653a (diff)
downloadmariadb-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.result5
-rw-r--r--mysql-test/t/func_json.test5
-rw-r--r--sql/item_jsonfunc.cc4
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)