Commit 7f6710e5 authored by Alexey Botchkov's avatar Alexey Botchkov

MDEV-11489 Assertion `0' failed in json_find_path.

        When the json was just a scalar value, json_extract tried
        to parse after the value ended.
parent 9ea5de30
......@@ -138,6 +138,9 @@ json_extract('[10, 20, [30, 40]]', '$[2][*]')
select json_extract('[10, 20, [{"a":3}, 30, 40]]', '$[2][*]');
json_extract('[10, 20, [{"a":3}, 30, 40]]', '$[2][*]')
[{"a":3}, 30, 40]
select json_extract('1', '$');
json_extract('1', '$')
1
select json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.b.k1', 'word');
json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.b.k1', 'word')
{"a":1, "b":{"c":1, "k1":"word"}, "d":[1, 2]}
......
......@@ -54,6 +54,7 @@ select json_extract('{"key0":true, "key1":"qwe"}', "$.key1");
select json_extract(json_object('foo', 'foobar'),'$');
select json_extract('[10, 20, [30, 40]]', '$[2][*]');
select json_extract('[10, 20, [{"a":3}, 30, 40]]', '$[2][*]');
select json_extract('1', '$');
select json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.b.k1', 'word');
select json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.d[3]', 3);
......
......@@ -476,9 +476,6 @@ String *Item_func_json_extract::val_str(String *str)
v_len= je.s.c_str - value;
}
if (json_scan_next(&je) && je.s.error)
goto error;
if (!multiple_values_found)
{
if (first_value == NULL)
......@@ -489,7 +486,6 @@ String *Item_func_json_extract::val_str(String *str)
*/
first_value= (const char *) value;
first_len= v_len;
continue;
}
else
{
......@@ -500,15 +496,20 @@ String *Item_func_json_extract::val_str(String *str)
}
}
if (str->append(", ", 2) ||
str->append((const char *) value, v_len))
if (multiple_values_found &&
(str->append(", ", 2) ||
str->append((const char *) value, v_len)))
goto error; /* Out of memory. */
}
if (je.s.error)
goto error;
if (json_scan_next(&je))
break;
}
}
if (je.s.error)
goto error;
if (first_value == NULL)
{
/* Nothing was found. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment