From c8bb43a9385cdb7a27f0702742a8d1e08a85befd Mon Sep 17 00:00:00 2001 From: Alexey Botchkov Date: Tue, 11 Sep 2018 14:37:45 +0400 Subject: MDEV-17121 JSON_ARRAY_APPEND. Extra comma added to the result when an json array is empty. --- sql/item_jsonfunc.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'sql/item_jsonfunc.cc') diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc index 4a837646451..1da53935441 100644 --- a/sql/item_jsonfunc.cc +++ b/sql/item_jsonfunc.cc @@ -1621,13 +1621,15 @@ String *Item_func_json_array_append::val_str(String *str) if (je.value_type == JSON_VALUE_ARRAY) { - if (json_skip_level(&je)) + int n_items; + if (json_skip_level_and_count(&je, &n_items)) goto js_error; ar_end= je.s.c_str - je.sav_c_len; str_rest_len= js->length() - (ar_end - (const uchar *) js->ptr()); str->q_append(js->ptr(), ar_end-(const uchar *) js->ptr()); - str->append(", ", 2); + if (n_items) + str->append(", ", 2); if (append_json_value(str, args[n_arg+1], &tmp_val)) goto return_null; /* Out of memory. */ -- cgit v1.2.1