Skip to content

Commit

Permalink
MDEV-13324 JSON_SET returns NULL instead of object.
Browse files Browse the repository at this point in the history
        Superfluous ',' was added to the JSON_SET result so it became
        invalid.
  • Loading branch information
Alexey Botchkov committed Sep 12, 2017
1 parent 49878be commit 467acc2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions mysql-test/r/func_json.result
Expand Up @@ -680,3 +680,6 @@ JSON_OBJECT('foo', '`')
SELECT JSON_OBJECT("foo", "bar`bar");
JSON_OBJECT("foo", "bar`bar")
{"foo": "bar`bar"}
SELECT JSON_SET('{}', '$.age', 87);
JSON_SET('{}', '$.age', 87)
{"age": 87}
3 changes: 1 addition & 2 deletions mysql-test/suite/json/r/json_no_table.result
Expand Up @@ -2109,10 +2109,9 @@ ERROR 42000: Incorrect parameter count in the call to native function 'json_set'
error ER_INVALID_JSON_TEXT_IN_PARAM
SELECT JSON_SET('{}', '$.name', JSON_EXTRACT('', '$'));
JSON_SET('{}', '$.name', JSON_EXTRACT('', '$'))
NULL
{"name": null}
Warnings:
Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_extract'
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_set' at position 2
select json_set('[1,2,3]', '$[2]', 4);
json_set('[1,2,3]', '$[2]', 4)
[1, 2, 4]
Expand Down
5 changes: 5 additions & 0 deletions mysql-test/t/func_json.test
Expand Up @@ -328,3 +328,8 @@ select JSON_EXTRACT('{"foo": "bar" foobar foo invalid ', '$.foo');
SELECT JSON_OBJECT('foo', '`');
SELECT JSON_OBJECT("foo", "bar`bar");

#
# MDEV-13324 JSON_SET returns NULL instead of object.
#
SELECT JSON_SET('{}', '$.age', 87);

6 changes: 5 additions & 1 deletion sql/item_jsonfunc.cc
Expand Up @@ -2450,6 +2450,8 @@ String *Item_func_json_insert::val_str(String *str)
}
else /*JSON_PATH_KEY*/
{
uint n_key= 0;

if (je.value_type != JSON_VALUE_OBJECT)
continue;

Expand All @@ -2461,6 +2463,7 @@ String *Item_func_json_insert::val_str(String *str)
json_string_set_str(&key_name, lp->key, lp->key_end);
if (json_key_matches(&je, &key_name))
goto v_found;
n_key++;
if (json_skip_key(&je))
goto js_error;
break;
Expand All @@ -2478,7 +2481,8 @@ String *Item_func_json_insert::val_str(String *str)
v_to= (const char *) (je.s.c_str - je.sav_c_len);
str->length(0);
if (append_simple(str, js->ptr(), v_to - js->ptr()) ||
str->append(", \"", 3) ||
(n_key > 0 && str->append(", ", 2)) ||
str->append("\"", 1) ||
append_simple(str, lp->key, lp->key_end - lp->key) ||
str->append("\":", 2) ||
append_json_value(str, args[n_arg+1], &tmp_val) ||
Expand Down

0 comments on commit 467acc2

Please sign in to comment.