diff options
author | Alexey Botchkov <holyfoot@askmonty.org> | 2016-12-04 14:49:06 +0400 |
---|---|---|
committer | Alexey Botchkov <holyfoot@askmonty.org> | 2016-12-05 01:03:30 +0400 |
commit | 12897a5bba8a7980a7ca20115bebfc8e5f704a31 (patch) | |
tree | 99664c8e0d134454f430c8f9599c8297f4fd9fba /sql/item_jsonfunc.cc | |
parent | b4cbaf0b7c8bc32b8528b2e22f2d2a89971b8dde (diff) | |
download | mariadb-git-12897a5bba8a7980a7ca20115bebfc8e5f704a31.tar.gz |
MDEV-11437 JSON_QUOTE function does not quote and uses wrong character set.
json_quote fixed.
Diffstat (limited to 'sql/item_jsonfunc.cc')
-rw-r--r-- | sql/item_jsonfunc.cc | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc index cf6bae91fec..00621bbfade 100644 --- a/sql/item_jsonfunc.cc +++ b/sql/item_jsonfunc.cc @@ -287,12 +287,12 @@ bool Item_func_json_query::check_and_get_value(json_engine_t *je, String *res, void Item_func_json_quote::fix_length_and_dec() { - collation.set(args[0]->collation); + collation.set(&my_charset_utf8mb4_bin); /* Odd but realistic worst case is when all characters of the argument turn into '\uXXXX\uXXXX', which is 12. */ - max_length= args[0]->max_length * 12; + max_length= args[0]->max_length * 12 + 2; } @@ -300,13 +300,16 @@ String *Item_func_json_quote::val_str(String *str) { String *s= args[0]->val_str(&tmp_s); - if ((null_value= args[0]->null_value)) + if ((null_value= (args[0]->null_value || + args[0]->result_type() != STRING_RESULT))) return NULL; str->length(0); - str->set_charset(s->charset()); + str->set_charset(&my_charset_utf8mb4_bin); - if (st_append_escaped(str, s)) + if (str->append("\"", 1) || + st_append_escaped(str, s) || + str->append("\"", 1)) { /* Report an error. */ null_value= 1; |