From 4e50c86040ac38325628b826594dc4d00a8f07d3 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Thu, 21 Nov 2024 13:10:22 +0000 Subject: [PATCH] Stop accidentally sending wchar_t as terminal input! When term_input_data_from_charset receives data in a specified character set (that isn't a negative number indicating "just send binary"), it was translating from that character set into wide- character Unicode, but then forgetting to translate back again into the terminal's configured character set. Introduced by the rewrite in commit 4f756d2a4db7678. Affected the answerback string sent in response to ^E, and I think potentially some paths through term_keyinput too, although I haven't quite worked out which ones would have been affected. --- terminal/terminal.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/terminal/terminal.c b/terminal/terminal.c index 27068bf6..e127ff6e 100644 --- a/terminal/terminal.c +++ b/terminal/terminal.c @@ -3506,14 +3506,19 @@ static strbuf *term_input_data_from_unicode( static strbuf *term_input_data_from_charset( Terminal *term, int codepage, const char *str, size_t len) { - strbuf *buf = strbuf_new(); - - if (codepage < 0) + if (codepage < 0) { + strbuf *buf = strbuf_new(); put_data(buf, str, len); - else - put_mb_to_wc(buf, codepage, str, len); + return buf; + } else { + strbuf *wide = strbuf_new(); + put_mb_to_wc(wide, codepage, str, len); + strbuf *buf = term_input_data_from_unicode( + term, (const wchar_t *)wide->s, wide->len / sizeof(wchar_t)); + strbuf_free(wide); + return buf; + } - return buf; } static inline void term_bracketed_paste_start(Terminal *term)