aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-01-27 09:44:28 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-01-27 09:54:37 +0000
commit7049c95b62312ac57cbc67a6030ddb77a75f66a1 (patch)
tree8c764775a90fb3b30fabcc1740b563384844e56c
parentselection: no xassert() in the releases/1.6 branch (diff)
selection: don’t replace \r\n and \n with \r in bracketed paste mode
-rw-r--r--selection.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/selection.c b/selection.c
index 4a63b538..b83331a6 100644
--- a/selection.c
+++ b/selection.c
@@ -1143,6 +1143,7 @@ struct clipboard_receive {
int read_fd;
int timeout_fd;
struct itimerspec timeout;
+ bool bracketed;
void (*decoder)(struct clipboard_receive *ctx, char *data, size_t size);
void (*finish)(struct clipboard_receive *ctx);
@@ -1254,7 +1255,15 @@ fdm_receive_decoder_uri(struct clipboard_receive *ctx, char *data, size_t size)
char *start = ctx->buf.data;
char *end = NULL;
- while ((end = memchr(start, '\r', ctx->buf.idx - (start - ctx->buf.data))) != NULL) {
+ while (true) {
+ for (end = start; end < &ctx->buf.data[ctx->buf.idx]; end++) {
+ if (*end == '\r' || *end == '\n')
+ break;
+ }
+
+ if (end >= &ctx->buf.data[ctx->buf.idx])
+ break;
+
decode_one_uri(ctx, start, end - start);
start = end + 1;
}
@@ -1319,12 +1328,13 @@ fdm_receive(struct fdm *fdm, int fd, int events, void *data)
break;
case '\n':
- p[i] = '\r';
+ if (!ctx->bracketed)
+ p[i] = '\r';
break;
case '\r':
/* Convert \r\n -> \r */
- if (i + 1 < left && p[i + 1] == '\n') {
+ if (!ctx->bracketed && i + 1 < left && p[i + 1] == '\n') {
ctx->decoder(ctx, p, i + 1);
assert(i + 2 <= left);
@@ -1399,6 +1409,7 @@ begin_receive_clipboard(struct terminal *term, int read_fd,
.read_fd = read_fd,
.timeout_fd = timeout_fd,
.timeout = timeout,
+ .bracketed = term->bracketed_paste,
.decoder = (mime_type == DATA_OFFER_MIME_URI_LIST
? &fdm_receive_decoder_uri
: &fdm_receive_decoder_plain),