summaryrefslogtreecommitdiff
path: root/src/eval.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-02-07 21:59:26 +0100
committerBram Moolenaar <Bram@vim.org>2016-02-07 21:59:26 +0100
commitae8eb3ca927f1b0ac2a6643da8699538cdc380f6 (patch)
tree16ccccdd92949c9f3642fed83f8bf4d22a89eb33 /src/eval.c
parent74f5e65bcc3d77ab879f56eb977f5038edccbcf8 (diff)
downloadvim-ae8eb3ca927f1b0ac2a6643da8699538cdc380f6.zip
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.
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/eval.c b/src/eval.c
index 787f0f034..e3edff6df 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -9924,7 +9924,10 @@ send_common(typval_T *argvars, char_u *text, int id, char *fun)
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_T *rettv)
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;