Skip to content

Commit 6352ec2

Browse files
author
Alexey Botchkov
committed
MDEV-12982 JSON_EXTRACT returns data for invalid JSON.
Let's check the validity to the end of the JSON.
1 parent 31774f0 commit 6352ec2

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

mysql-test/r/func_json.result

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,3 +669,8 @@ JSON_EXTRACT('{\"asdf\":true}', "$.\"asdf\"") = 1
669669
select JSON_EXTRACT('{\"input1\":\"\\u00f6\"}', '$.\"input1\"');
670670
JSON_EXTRACT('{\"input1\":\"\\u00f6\"}', '$.\"input1\"')
671671
"\u00f6"
672+
select JSON_EXTRACT('{"foo": "bar" foobar foo invalid ', '$.foo');
673+
JSON_EXTRACT('{"foo": "bar" foobar foo invalid ', '$.foo')
674+
NULL
675+
Warnings:
676+
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_extract' at position 15

mysql-test/t/func_json.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,8 @@ select JSON_EXTRACT('{\"asdf\":true}', "$.\"asdf\"") = false;
317317
select JSON_EXTRACT('{\"asdf\":true}', "$.\"asdf\"") = 1;
318318
select JSON_EXTRACT('{\"input1\":\"\\u00f6\"}', '$.\"input1\"');
319319

320+
#
321+
# MDEV-129892 JSON_EXTRACT returns data for invalid JSON
322+
#
323+
select JSON_EXTRACT('{"foo": "bar" foobar foo invalid ', '$.foo');
324+

sql/item_jsonfunc.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,11 @@ String *Item_func_json_extract::read_json(String *str,
821821
not_first_value= 1;
822822

823823
if (!possible_multiple_values)
824+
{
825+
/* Loop to the end of the JSON just to make sure it's valid. */
826+
while (json_get_path_next(&je, &p) == 0) {}
824827
break;
828+
}
825829
}
826830

827831
if (je.s.error)

0 commit comments

Comments
 (0)