Skip to content

Commit ae8eb3c

Browse files
committed
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.
1 parent 74f5e65 commit ae8eb3c

4 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/channel.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,4 +1514,17 @@ set_ref_in_channel(int copyID)
15141514
}
15151515
return abort;
15161516
}
1517+
1518+
/*
1519+
* Return the mode of channel "idx".
1520+
* If "idx" is invalid returns MODE_JSON.
1521+
*/
1522+
ch_mode_T
1523+
channel_get_mode(int idx)
1524+
{
1525+
if (idx < 0 || idx >= channel_count)
1526+
return MODE_JSON;
1527+
return channels[idx].ch_mode;
1528+
}
1529+
15171530
#endif /* FEAT_CHANNEL */

src/eval.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9924,7 +9924,10 @@ send_common(typval_T *argvars, char_u *text, int id, char *fun)
99249924

99259925
ch_idx = get_channel_arg(&argvars[0]);
99269926
if (ch_idx < 0)
9927+
{
9928+
EMSG(_(e_invarg));
99279929
return -1;
9930+
}
99289931

99299932
if (argvars[2].v_type != VAR_UNKNOWN)
99309933
{
@@ -9952,13 +9955,29 @@ f_ch_sendexpr(typval_T *argvars, typval_T *rettv)
99529955
typval_T *listtv;
99539956
int ch_idx;
99549957
int id;
9958+
ch_mode_T ch_mode;
99559959

99569960
/* return an empty string by default */
99579961
rettv->v_type = VAR_STRING;
99589962
rettv->vval.v_string = NULL;
99599963

9964+
ch_idx = get_channel_arg(&argvars[0]);
9965+
if (ch_idx < 0)
9966+
{
9967+
EMSG(_(e_invarg));
9968+
return;
9969+
}
9970+
9971+
ch_mode = channel_get_mode(ch_idx);
9972+
if (ch_mode == MODE_RAW)
9973+
{
9974+
EMSG(_("E912: cannot use ch_sendexpr() with a raw channel"));
9975+
return;
9976+
}
9977+
99609978
id = channel_get_id();
9961-
text = json_encode_nr_expr(id, &argvars[1], 0);
9979+
text = json_encode_nr_expr(id, &argvars[1],
9980+
ch_mode == MODE_JS ? JSON_JS : 0);
99629981
if (text == NULL)
99639982
return;
99649983

src/proto/channel.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ int channel_select_setup(int maxfd_in, void *rfds_in);
2424
int channel_select_check(int ret_in, void *rfds_in);
2525
int channel_parse_messages(void);
2626
int set_ref_in_channel(int copyID);
27+
ch_mode_T channel_get_mode(int idx);
2728
/* vim: set ft=c : */

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,8 @@ static char *(features[]) =
747747

748748
static int included_patches[] =
749749
{ /* Add new patch number below this line */
750+
/**/
751+
1288,
750752
/**/
751753
1287,
752754
/**/

0 commit comments

Comments
 (0)