]> granicus.if.org Git - vim/commitdiff
patch 7.4.1288 v7.4.1288
authorBram Moolenaar <Bram@vim.org>
Sun, 7 Feb 2016 20:59:26 +0000 (21:59 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 7 Feb 2016 20:59:26 +0000 (21:59 +0100)
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.

src/channel.c
src/eval.c
src/proto/channel.pro
src/version.c

index 8e36808a4bee2060676a3e2decfcf3232ecd5065..fef6de504af255948f4d96cd2e6e426a727f1a92 100644 (file)
@@ -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 */
index 787f0f03431e1f606dbbb88363bbc961d438942f..e3edff6df76b5fd8debaeef96d61eafb0ca3afbe 100644 (file)
@@ -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;
 
index 693d2c223d3005d49ef0912664633aa1c6550063..4de1720139a8c43404b23eb602d6995f8a8d2c2d 100644 (file)
@@ -24,4 +24,5 @@ int channel_select_setup(int maxfd_in, void *rfds_in);
 int channel_select_check(int ret_in, void *rfds_in);
 int channel_parse_messages(void);
 int set_ref_in_channel(int copyID);
+ch_mode_T channel_get_mode(int idx);
 /* vim: set ft=c : */
index a857cf1fc65f847881c0c065f25a31f0815ba3eb..220b2c5cbff409580adbfacff4f7c9277bc69c0e 100644 (file)
@@ -747,6 +747,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1288,
 /**/
     1287,
 /**/