mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
MDEV-11569 JSON_ARRAY_INSERT produces an invalid result.
String insertion fixed.
This commit is contained in:
@@ -75,10 +75,13 @@ json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[4]', 'x')
|
|||||||
["a", {"b": [1, 2]}, [3, 4], "x"]
|
["a", {"b": [1, 2]}, [3, 4], "x"]
|
||||||
select json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[1].b[0]', 'x');
|
select json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[1].b[0]', 'x');
|
||||||
json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[1].b[0]', 'x')
|
json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[1].b[0]', 'x')
|
||||||
["a", {"b": [ "x",1, 2]}, [3, 4]]
|
["a", {"b": ["x", 1, 2]}, [3, 4]]
|
||||||
select json_array_insert('true', '$', 1);
|
select json_array_insert('true', '$', 1);
|
||||||
json_array_insert('true', '$', 1)
|
json_array_insert('true', '$', 1)
|
||||||
NULL
|
NULL
|
||||||
|
select json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[2][1]', 'y');
|
||||||
|
json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[2][1]', 'y')
|
||||||
|
["a", {"b": [1, 2]}, [3, "y", 4]]
|
||||||
select json_contains('{"k1":123, "k2":345}', '123', '$.k1');
|
select json_contains('{"k1":123, "k2":345}', '123', '$.k1');
|
||||||
json_contains('{"k1":123, "k2":345}', '123', '$.k1')
|
json_contains('{"k1":123, "k2":345}', '123', '$.k1')
|
||||||
1
|
1
|
||||||
|
@@ -30,6 +30,7 @@ select json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[3]', 'x');
|
|||||||
select json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[4]', 'x');
|
select json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[4]', 'x');
|
||||||
select json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[1].b[0]', 'x');
|
select json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[1].b[0]', 'x');
|
||||||
select json_array_insert('true', '$', 1);
|
select json_array_insert('true', '$', 1);
|
||||||
|
select json_array_insert('["a", {"b": [1, 2]}, [3, 4]]', '$[2][1]', 'y');
|
||||||
|
|
||||||
select json_contains('{"k1":123, "k2":345}', '123', '$.k1');
|
select json_contains('{"k1":123, "k2":345}', '123', '$.k1');
|
||||||
select json_contains('"you"', '"you"');
|
select json_contains('"you"', '"you"');
|
||||||
|
@@ -1396,27 +1396,19 @@ String *Item_func_json_array_insert::val_str(String *str)
|
|||||||
item_pos= 0;
|
item_pos= 0;
|
||||||
n_item= 0;
|
n_item= 0;
|
||||||
|
|
||||||
while (json_scan_next(&je) == 0 &&
|
while (json_scan_next(&je) == 0 && je.state != JST_ARRAY_END)
|
||||||
je.state != JST_ARRAY_END && item_pos == 0)
|
|
||||||
{
|
{
|
||||||
switch (je.state)
|
DBUG_ASSERT(je.state == JST_VALUE);
|
||||||
|
if (n_item == c_path->p.last_step[1].n_item)
|
||||||
{
|
{
|
||||||
case JST_VALUE:
|
item_pos= (const char *) je.s.c_str;
|
||||||
if (n_item == c_path->p.last_step[1].n_item)
|
|
||||||
{
|
|
||||||
item_pos= (const char *) je.s.c_str;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
n_item++;
|
|
||||||
break;
|
|
||||||
case JST_OBJ_START:
|
|
||||||
case JST_ARRAY_START:
|
|
||||||
if (json_skip_level(&je))
|
|
||||||
break;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
n_item++;
|
||||||
|
|
||||||
|
if (json_read_value(&je) ||
|
||||||
|
(!json_value_scalar(&je) && json_skip_level(&je)))
|
||||||
|
goto js_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (je.s.error)
|
if (je.s.error)
|
||||||
@@ -1424,16 +1416,27 @@ String *Item_func_json_array_insert::val_str(String *str)
|
|||||||
|
|
||||||
str->length(0);
|
str->length(0);
|
||||||
str->set_charset(js->charset());
|
str->set_charset(js->charset());
|
||||||
if (!item_pos)
|
if (item_pos)
|
||||||
|
{
|
||||||
|
if (append_simple(str, js->ptr(), item_pos - js->ptr()) ||
|
||||||
|
(n_item > 0 && str->append(" ", 1)) ||
|
||||||
|
append_json_value(str, args[n_arg+1], &tmp_val) ||
|
||||||
|
str->append(",", 1) ||
|
||||||
|
(n_item == 0 && str->append(" ", 1)) ||
|
||||||
|
append_simple(str, item_pos, js->end() - item_pos))
|
||||||
|
goto return_null; /* Out of memory. */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Insert position wasn't found - append to the array. */
|
||||||
|
DBUG_ASSERT(je.state == JST_ARRAY_END);
|
||||||
item_pos= (const char *) (je.s.c_str - je.sav_c_len);
|
item_pos= (const char *) (je.s.c_str - je.sav_c_len);
|
||||||
|
if (append_simple(str, js->ptr(), item_pos - js->ptr()) ||
|
||||||
if (append_simple(str, js->ptr(), item_pos - js->ptr()) ||
|
(n_item > 0 && str->append(", ", 2)) ||
|
||||||
((je.state == JST_ARRAY_END) ?
|
append_json_value(str, args[n_arg+1], &tmp_val) ||
|
||||||
(n_item > 0 && str->append(", ", 2)) : str->append(" ", 1)) ||
|
append_simple(str, item_pos, js->end() - item_pos))
|
||||||
append_json_value(str, args[n_arg+1], &tmp_val) ||
|
goto return_null; /* Out of memory. */
|
||||||
(je.state != JST_ARRAY_END && str->append(",", 1)) ||
|
}
|
||||||
append_simple(str, item_pos, js->end() - item_pos))
|
|
||||||
goto return_null; /* Out of memory. */
|
|
||||||
|
|
||||||
{
|
{
|
||||||
/* Swap str and js. */
|
/* Swap str and js. */
|
||||||
|
Reference in New Issue
Block a user