Skip to content

Commit

Permalink
MDEV-11489 Assertion `0' failed in json_find_path.
Browse files Browse the repository at this point in the history
        When the json was just a scalar value, json_extract tried
        to parse after the value ended.
  • Loading branch information
Alexey Botchkov committed Dec 8, 2016
1 parent 9ea5de3 commit 7f6710e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
3 changes: 3 additions & 0 deletions mysql-test/r/func_json.result
Original file line number Diff line number Diff line change
Expand Up @@ -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]}
Expand Down
1 change: 1 addition & 0 deletions mysql-test/t/func_json.test
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 10 additions & 9 deletions sql/item_jsonfunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -489,7 +486,6 @@ String *Item_func_json_extract::val_str(String *str)
*/
first_value= (const char *) value;
first_len= v_len;
continue;
}
else
{
Expand All @@ -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. */
Expand Down

0 comments on commit 7f6710e

Please sign in to comment.