Skip to content

Commit

Permalink
MDEV-11473 JSON_REMOVE returns invalid results.
Browse files Browse the repository at this point in the history
        Item_func_json_remove::val_str fixed.
  • Loading branch information
Alexey Botchkov committed Dec 5, 2016
1 parent 7e03c67 commit df87dce
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
2 changes: 1 addition & 1 deletion mysql-test/r/func_json.result
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ json_remove(@j, '$[0]')
[ ["b", "c"], "d"]
select json_remove(@j, '$[1]');
json_remove(@j, '$[1]')
["a" "d"]
["a", "d"]
select json_remove(@j, '$[2]');
json_remove(@j, '$[2]')
["a", ["b", "c"]]
Expand Down
4 changes: 1 addition & 3 deletions sql/item_jsonfunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1667,9 +1667,7 @@ String *Item_func_json_remove::val_str(String *str)
rem_start= (const char *) (je.s.c_str - je.sav_c_len);
json_string_set_str(&key_name, lp->key, lp->key_end);
if (json_key_matches(&je, &key_name))
{
goto v_found;
}

if (json_skip_key(&je))
goto error;
Expand All @@ -1693,7 +1691,7 @@ String *Item_func_json_remove::val_str(String *str)
if (json_skip_key(&je) || json_scan_next(&je))
goto error;

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

str->length(0);
Expand Down

0 comments on commit df87dce

Please sign in to comment.