summaryrefslogtreecommitdiff
path: root/sql/item_jsonfunc.cc
diff options
context:
space:
mode:
authorAlexey Botchkov <holyfoot@askmonty.org>2017-09-12 14:40:18 +0400
committerAlexey Botchkov <holyfoot@askmonty.org>2017-09-12 14:40:18 +0400
commit467acc2119e9408b640915f767515b9242a4d6a3 (patch)
treee27df35f4f790dbdad2da564ecd75160a48a36da /sql/item_jsonfunc.cc
parent49878be33107893452155bf1099cd600cc23fb91 (diff)
downloadmariadb-git-467acc2119e9408b640915f767515b9242a4d6a3.tar.gz
MDEV-13324 JSON_SET returns NULL instead of object.
Superfluous ',' was added to the JSON_SET result so it became invalid.
Diffstat (limited to 'sql/item_jsonfunc.cc')
-rw-r--r--sql/item_jsonfunc.cc6
1 files changed, 5 insertions, 1 deletions
diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc
index c30ce45bfb2..e5544c6265d 100644
--- a/sql/item_jsonfunc.cc
+++ b/sql/item_jsonfunc.cc
@@ -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;
@@ -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;
@@ -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) ||