From 7c8e63e1719ff47f050692b6bf288fd9f1af9981 Mon Sep 17 00:00:00 2001 From: Siarzhuk Zharski Date: Mon, 20 May 2013 13:50:44 +0200 Subject: [PATCH] Terminal: fix handling utf-8 characters in OSC commands Process the Operating System Control command in multibyte-aware way. That fixes corresponding behavior for latest versions of Midnight Commander; --- src/apps/terminal/TermParse.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/apps/terminal/TermParse.cpp b/src/apps/terminal/TermParse.cpp index c2b1edacd9..b86fbe52f3 100644 --- a/src/apps/terminal/TermParse.cpp +++ b/src/apps/terminal/TermParse.cpp @@ -1048,8 +1048,19 @@ TermParse::EscParse() uchar params[512]; // fill the buffer until BEL, ST or something else. bool isParsed = false; + int32 skipCount = 0; // take care about UTF-8 characters for (uint i = 0; !isParsed && i < sizeof(params); i++) { params[i] = _NextParseChar(); + + if (skipCount > 0) { + skipCount--; + continue; + } + + skipCount = UTF8Char::ByteCount(params[i]) - 1; + if (skipCount > 0) + continue; + switch (params[i]) { // BEL case 0x07: @@ -1074,6 +1085,9 @@ TermParse::EscParse() params[i] = '\0'; } + // watchdog for the 'end of buffer' case + params[sizeof(params) - 1] = '\0'; + if (isParsed) _ProcessOperatingSystemControls(params);