Mercurial > vim
changeset 7986:8e0d4cd8157a v7.4.1288
commit https://github.com/vim/vim/commit/ae8eb3ca927f1b0ac2a6643da8699538cdc380f6
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Feb 7 21:59:26 2016 +0100
patch 7.4.1288
Problem: ch_sendexpr() does not use JS encoding.
Solution: Use the encoding that fits the channel mode. Refuse using
ch_sendexpr() on a raw channel.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 07 Feb 2016 22:00:05 +0100 |
parents | fd76e567bf86 |
children | f49f393da704 |
files | src/channel.c src/eval.c src/proto/channel.pro src/version.c |
diffstat | 4 files changed, 36 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/channel.c +++ b/src/channel.c @@ -1514,4 +1514,17 @@ set_ref_in_channel(int copyID) } return abort; } + +/* + * Return the mode of channel "idx". + * If "idx" is invalid returns MODE_JSON. + */ + ch_mode_T +channel_get_mode(int idx) +{ + if (idx < 0 || idx >= channel_count) + return MODE_JSON; + return channels[idx].ch_mode; +} + #endif /* FEAT_CHANNEL */
--- a/src/eval.c +++ b/src/eval.c @@ -9924,7 +9924,10 @@ send_common(typval_T *argvars, char_u *t ch_idx = get_channel_arg(&argvars[0]); if (ch_idx < 0) + { + EMSG(_(e_invarg)); return -1; + } if (argvars[2].v_type != VAR_UNKNOWN) { @@ -9952,13 +9955,29 @@ f_ch_sendexpr(typval_T *argvars, typval_ typval_T *listtv; int ch_idx; int id; + ch_mode_T ch_mode; /* return an empty string by default */ rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; + ch_idx = get_channel_arg(&argvars[0]); + if (ch_idx < 0) + { + EMSG(_(e_invarg)); + return; + } + + ch_mode = channel_get_mode(ch_idx); + if (ch_mode == MODE_RAW) + { + EMSG(_("E912: cannot use ch_sendexpr() with a raw channel")); + return; + } + id = channel_get_id(); - text = json_encode_nr_expr(id, &argvars[1], 0); + text = json_encode_nr_expr(id, &argvars[1], + ch_mode == MODE_JS ? JSON_JS : 0); if (text == NULL) return;