diff options
author | Sergei Golubchik <serg@mariadb.org> | 2018-02-06 14:50:50 +0100 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2018-02-06 14:50:50 +0100 |
commit | 4771ae4b22d2bdef0aafc563570c71d4636a2493 (patch) | |
tree | d115bd7c68b1e6feab68ff6fcd547e0c86c79296 /mysys/ma_dyncol.c | |
parent | 60f51af755ea9d07c20a596ba21de184816fa265 (diff) | |
parent | 0c25e58db6b045df92c209d396031cac5b528bbf (diff) | |
download | mariadb-git-4771ae4b22d2bdef0aafc563570c71d4636a2493.tar.gz |
Merge branch 'github/10.1' into 10.2
Diffstat (limited to 'mysys/ma_dyncol.c')
-rw-r--r-- | mysys/ma_dyncol.c | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/mysys/ma_dyncol.c b/mysys/ma_dyncol.c index 3c15e373182..2e00ca72f74 100644 --- a/mysys/ma_dyncol.c +++ b/mysys/ma_dyncol.c @@ -3818,6 +3818,58 @@ end: DBUG_RETURN(rc); } +static +my_bool dynstr_append_json_quoted(DYNAMIC_STRING *str, + const char *append, size_t len) +{ + uint additional= ((str->alloc_increment && str->alloc_increment > 6) ? + str->alloc_increment : + 10); + uint lim= additional; + uint i; + if (dynstr_realloc(str, len + additional + 2)) + return TRUE; + str->str[str->length++]= '"'; + for (i= 0; i < len; i++) + { + register char c= append[i]; + if (unlikely(c <= 0x1F)) + { + if (lim < 5) + { + if (dynstr_realloc(str, additional)) + return TRUE; + lim+= additional; + } + lim-= 5; + str->str[str->length++]= '\\'; + str->str[str->length++]= 'u'; + str->str[str->length++]= '0'; + str->str[str->length++]= '0'; + str->str[str->length++]= (c < 0x10 ? '0' : '1'); + c%= 0x10; + str->str[str->length++]= (c < 0xA ? '0' + c : 'A' + (c - 0xA)); + } + else + { + if (c == '"' || c == '\\') + { + if (!lim) + { + if (dynstr_realloc(str, additional)) + return TRUE; + lim= additional; + } + lim--; + str->str[str->length++]= '\\'; + } + str->str[str->length++]= c; + } + } + str->str[str->length++]= '"'; + return FALSE; +} + enum enum_dyncol_func_result mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val, @@ -3883,7 +3935,10 @@ mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val, return ER_DYNCOL_RESOURCE; } if (quote) - rc= dynstr_append_quoted(str, from, len, quote); + if (quote == DYNCOL_JSON_ESC) + rc= dynstr_append_json_quoted(str, from, len); + else + rc= dynstr_append_quoted(str, from, len, quote); else rc= dynstr_append_mem(str, from, len); if (alloc) @@ -4183,7 +4238,8 @@ mariadb_dyncol_json_internal(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json, } else { - if ((rc= mariadb_dyncol_val_str(json, &val, DYNCOL_UTF, '"')) < 0) + if ((rc= mariadb_dyncol_val_str(json, &val, DYNCOL_UTF, DYNCOL_JSON_ESC)) + < 0) goto err; } } |