Skip to content

Commit df87dce

Browse files
author
Alexey Botchkov
committed
MDEV-11473 JSON_REMOVE returns invalid results.
Item_func_json_remove::val_str fixed.
1 parent 7e03c67 commit df87dce

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

mysql-test/r/func_json.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ json_remove(@j, '$[0]')
150150
[ ["b", "c"], "d"]
151151
select json_remove(@j, '$[1]');
152152
json_remove(@j, '$[1]')
153-
["a" "d"]
153+
["a", "d"]
154154
select json_remove(@j, '$[2]');
155155
json_remove(@j, '$[2]')
156156
["a", ["b", "c"]]

sql/item_jsonfunc.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,9 +1667,7 @@ String *Item_func_json_remove::val_str(String *str)
16671667
rem_start= (const char *) (je.s.c_str - je.sav_c_len);
16681668
json_string_set_str(&key_name, lp->key, lp->key_end);
16691669
if (json_key_matches(&je, &key_name))
1670-
{
16711670
goto v_found;
1672-
}
16731671

16741672
if (json_skip_key(&je))
16751673
goto error;
@@ -1693,7 +1691,7 @@ String *Item_func_json_remove::val_str(String *str)
16931691
if (json_skip_key(&je) || json_scan_next(&je))
16941692
goto error;
16951693

1696-
rem_end= (je.state == JST_VALUE) ?
1694+
rem_end= (je.state == JST_VALUE && n_item == 0) ?
16971695
(const char *) je.s.c_str : (const char *) (je.s.c_str - je.sav_c_len);
16981696

16991697
str->length(0);

0 commit comments

Comments
 (0)