From aa4fcc49a29bb55928d5d519c179a1ba3f9d71b7 Mon Sep 17 00:00:00 2001 From: Mustafa M Date: Thu, 3 Sep 2020 21:37:28 +0200 Subject: [PATCH] win,tty: pass through utf-16 surrogate pairs On Windows allow utf-16 surrogate pars to pass through, which allows conhost on newer Windows versions and other terminal emulators to be able to render them. Fixes: https://github.com/libuv/libuv/issues/2909 PR-URL: https://github.com/libuv/libuv/pull/2971 Reviewed-By: Ben Noordhuis Reviewed-By: Jameson Nash --- src/win/tty.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/win/tty.c b/src/win/tty.c index 4604fb0c..1b9d4f85 100644 --- a/src/win/tty.c +++ b/src/win/tty.c @@ -2122,13 +2122,6 @@ static int uv_tty_write_bufs(uv_tty_t* handle, abort(); } - /* We wouldn't mind emitting utf-16 surrogate pairs. Too bad, the windows - * console doesn't really support UTF-16, so just emit the replacement - * character. */ - if (utf8_codepoint > 0xffff) { - utf8_codepoint = UNICODE_REPLACEMENT_CHARACTER; - } - if (utf8_codepoint == 0x0a || utf8_codepoint == 0x0d) { /* EOL conversion - emit \r\n when we see \n. */ @@ -2155,6 +2148,12 @@ static int uv_tty_write_bufs(uv_tty_t* handle, ENSURE_BUFFER_SPACE(1); utf16_buf[utf16_buf_used++] = (WCHAR) utf8_codepoint; previous_eol = 0; + } else { + ENSURE_BUFFER_SPACE(2); + utf8_codepoint -= 0x10000; + utf16_buf[utf16_buf_used++] = (WCHAR) (utf8_codepoint / 0x400 + 0xD800); + utf16_buf[utf16_buf_used++] = (WCHAR) (utf8_codepoint % 0x400 + 0xDC00); + previous_eol = 0; } } }