Skip to content

Commit 2368917

Browse files
committed
patch 7.4.1325
Problem: Channel test fails on difference between Unix and DOS line endings. Solution: Strip off CR. Make assert show difference better.
1 parent 38a5563 commit 2368917

3 files changed

Lines changed: 46 additions & 5 deletions

File tree

src/channel.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,8 @@ channel_save(channel_T *channel, char_u *buf, int len)
12621262
{
12631263
readq_T *node;
12641264
readq_T *head = &channel->ch_head;
1265+
char_u *p;
1266+
int i;
12651267

12661268
node = (readq_T *)alloc(sizeof(readq_T));
12671269
if (node == NULL)
@@ -1272,8 +1274,13 @@ channel_save(channel_T *channel, char_u *buf, int len)
12721274
vim_free(node);
12731275
return FAIL; /* out of memory */
12741276
}
1275-
mch_memmove(node->rq_buffer, buf, (size_t)len);
1276-
node->rq_buffer[len] = NUL;
1277+
1278+
/* TODO: don't strip CR when channel is in raw mode */
1279+
p = node->rq_buffer;
1280+
for (i = 0; i < len; ++i)
1281+
if (buf[i] != CAR || i + 1 >= len || buf[i + 1] != NL)
1282+
*p++ = buf[i];
1283+
*p = NUL;
12771284

12781285
/* append node to the tail of the queue */
12791286
node->rq_next = NULL;

src/eval.c

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9183,6 +9183,38 @@ prepare_assert_error(garray_T *gap)
91839183
ga_concat(gap, (char_u *)": ");
91849184
}
91859185

9186+
/*
9187+
* Append "str" to "gap", escaping unprintable characters.
9188+
* Changes NL to \n, CR to \r, etc.
9189+
*/
9190+
static void
9191+
ga_concat_esc(garray_T *gap, char_u *str)
9192+
{
9193+
char_u *p;
9194+
char_u buf[NUMBUFLEN];
9195+
9196+
for (p = str; *p != NUL; ++p)
9197+
switch (*p)
9198+
{
9199+
case BS: ga_concat(gap, (char_u *)"\\b"); break;
9200+
case ESC: ga_concat(gap, (char_u *)"\\e"); break;
9201+
case FF: ga_concat(gap, (char_u *)"\\f"); break;
9202+
case NL: ga_concat(gap, (char_u *)"\\n"); break;
9203+
case TAB: ga_concat(gap, (char_u *)"\\t"); break;
9204+
case CAR: ga_concat(gap, (char_u *)"\\r"); break;
9205+
case '\\': ga_concat(gap, (char_u *)"\\\\"); break;
9206+
default:
9207+
if (*p < ' ')
9208+
{
9209+
vim_snprintf((char *)buf, NUMBUFLEN, "\\x%02x", *p);
9210+
ga_concat(gap, buf);
9211+
}
9212+
else
9213+
ga_append(gap, *p);
9214+
break;
9215+
}
9216+
}
9217+
91869218
/*
91879219
* Fill "gap" with information about an assert error.
91889220
*/
@@ -9207,13 +9239,13 @@ fill_assert_error(
92079239
ga_concat(gap, (char_u *)"Expected ");
92089240
if (exp_str == NULL)
92099241
{
9210-
ga_concat(gap, tv2string(exp_tv, &tofree, numbuf, 0));
9242+
ga_concat_esc(gap, tv2string(exp_tv, &tofree, numbuf, 0));
92119243
vim_free(tofree);
92129244
}
92139245
else
9214-
ga_concat(gap, exp_str);
9246+
ga_concat_esc(gap, exp_str);
92159247
ga_concat(gap, (char_u *)" but got ");
9216-
ga_concat(gap, tv2string(got_tv, &tofree, numbuf, 0));
9248+
ga_concat_esc(gap, tv2string(got_tv, &tofree, numbuf, 0));
92179249
vim_free(tofree);
92189250
}
92199251
}

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+
1325,
750752
/**/
751753
1324,
752754
/**/

0 commit comments

Comments
 (0)