From 16ee36dbe317406004817ac1e28b4c860853fdf7 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Fri, 3 May 2019 23:26:11 +0200 Subject: [PATCH] termio: decode pasted string as utf8 and skip some codepoints Should fix issue pasting codepoints that fit on multiple bytes --- src/bin/termio.c | 37 ++++++++++++++++++++----------------- src/bin/termpty.c | 2 +- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/bin/termio.c b/src/bin/termio.c index 3889ecc7..50180266 100644 --- a/src/bin/termio.c +++ b/src/bin/termio.c @@ -1033,34 +1033,37 @@ _getsel_cb(void *data, if (buf) { char *s = ev->data; - size_t i, pos = 0; + int i, j, pos = 0, prev_i; /* apparently we have to convert \n into \r in terminal land. */ - for (i = 0; i < ev->len && s[i]; i++) + for (i = 0; i < (int)ev->len && s[i];) { + Eina_Unicode g = 0; + + prev_i = i; + g = eina_unicode_utf8_next_get(s, &i); /* Skip escape codes as a security measure */ - if ((s[i] < '\n') || - ((s[i] > '\n') && (s[i] < ' '))) + if ((g < '\n') || + ((g > '\n') && (g < ' '))) { - continue; + continue; } - buf[pos] = s[i]; - if (buf[pos] == '\n') - buf[pos] = '\r'; - pos++; + for (j = prev_i; j < i; j++) + buf[pos++] = s[j]; + if (g == '\n') + buf[pos++] = '\r'; } if (pos) { + if (sd->pty->bracketed_paste) + termpty_write(sd->pty, "\x1b[200~", + sizeof("\x1b[200~") - 1); - if (sd->pty->bracketed_paste) - termpty_write(sd->pty, "\x1b[200~", - sizeof("\x1b[200~") - 1); + termpty_write(sd->pty, buf, pos); - termpty_write(sd->pty, buf, pos); - - if (sd->pty->bracketed_paste) - termpty_write(sd->pty, "\x1b[201~", - sizeof("\x1b[201~") - 1); + if (sd->pty->bracketed_paste) + termpty_write(sd->pty, "\x1b[201~", + sizeof("\x1b[201~") - 1); } free(buf); diff --git a/src/bin/termpty.c b/src/bin/termpty.c index 1017c910..94b8e74e 100644 --- a/src/bin/termpty.c +++ b/src/bin/termpty.c @@ -302,7 +302,7 @@ _fd_read_do(Termpty *ty, Ecore_Fd_Handler *fd_handler, Eina_Bool false_on_empty) j = 0; for (i = 0; i < len;) { - int g = 0, prev_i = i; + Eina_Unicode g = 0, prev_i = i; if (buf[i]) {