From: zeertzjq Date: Fri, 6 Feb 2026 09:48:20 +0000 (+0000) Subject: patch 9.1.2134: Terminal doesn't handle split UTF-8 sequence after ASCII X-Git-Tag: v9.1.2134^0 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b24a1d9291b2d7fe202237a5d531076a095887d6;p=thirdparty%2Fvim.git patch 9.1.2134: Terminal doesn't handle split UTF-8 sequence after ASCII Problem: Terminal doesn't handle split UTF-8 sequence after ASCII. Solution: Only use one UTF-8 encoding state per vterm state (zeertzjq). fixes: #16559 closes: #18640 Signed-off-by: zeertzjq Signed-off-by: Christian Brabandt --- diff --git a/runtime/doc/version9.txt b/runtime/doc/version9.txt index 5b43fa91bf..73083398b3 100644 --- a/runtime/doc/version9.txt +++ b/runtime/doc/version9.txt @@ -52486,4 +52486,8 @@ Patch 9.1.2133 Problem: Another case of buffer overflow with 'helpfile'. Solution: Leave room for "tags" in the buffer (zeertzjq). +Patch 9.1.2134 +Problem: Terminal doesn't handle split UTF-8 sequence after ASCII. +Solution: Only use one UTF-8 encoding state per vterm state (zeertzjq). + vim:tw=78:ts=8:noet:ft=help:norl:fdm=manual:nofoldenable diff --git a/src/libvterm/src/state.c b/src/libvterm/src/state.c index ee36ad4c2d..aff97b0768 100644 --- a/src/libvterm/src/state.c +++ b/src/libvterm/src/state.c @@ -297,6 +297,8 @@ static int on_text(const char bytes[], size_t len, void *user) !(bytes[eaten] & 0x80) ? &state->encoding[state->gl_set] : state->vt->mode.utf8 ? &state->encoding_utf8 : &state->encoding[state->gr_set]; + if (encoding->enc == state->encoding_utf8.enc) + encoding = &state->encoding_utf8; // Only use one UTF-8 encoding state. (*encoding->enc->decode)(encoding->enc, encoding->data, codepoints, &npoints, state->gsingle_set ? 1 : (int)maxpoints, diff --git a/src/libvterm/t/14state_encoding.test b/src/libvterm/t/14state_encoding.test index b1f5d69853..2fd90e4386 100644 --- a/src/libvterm/t/14state_encoding.test +++ b/src/libvterm/t/14state_encoding.test @@ -103,3 +103,12 @@ PUSH "AB\xc4\x88D" putglyph 0x0042 1 0,1 putglyph 0x0108 1 0,2 putglyph 0x0044 1 0,3 + +!Split UTF-8 after US-ASCII +RESET +PUSH "AB\xc4" + putglyph 0x0041 1 0,0 + putglyph 0x0042 1 0,1 +PUSH "\x88D" + putglyph 0x0108 1 0,2 + putglyph 0x0044 1 0,3 diff --git a/src/testdir/test_terminal3.vim b/src/testdir/test_terminal3.vim index ff8f8c206b..b637a66528 100644 --- a/src/testdir/test_terminal3.vim +++ b/src/testdir/test_terminal3.vim @@ -1124,4 +1124,28 @@ func Test_terminal_backspace_on_windows() let $PROMPT = save_prompt endfunc +func Test_terminal_split_utf8() + CheckUnix + + let buf = term_start('cat', {}) + let chan = buf->term_getjob()->job_getchannel() + call ch_sendraw(chan, "1: \xc3") + call WaitForAssert({-> assert_equal('1: ', term_getline(buf, 1))}) + call ch_sendraw(chan, "\xa5\xcc\xb2\n") + call WaitForAssert({-> assert_equal('1: å̲', term_getline(buf, 1))}) + call WaitForAssert({-> assert_equal('1: å̲', term_getline(buf, 2))}) + call ch_sendraw(chan, "2: \xc3\xa5") + call WaitForAssert({-> assert_equal('2: å', term_getline(buf, 3))}) + call ch_sendraw(chan, "\xcc\xb2\n") + call WaitForAssert({-> assert_equal('2: å̲', term_getline(buf, 3))}) + call WaitForAssert({-> assert_equal('2: å̲', term_getline(buf, 4))}) + call ch_sendraw(chan, "3: \xc3\xa5\xcc") + call WaitForAssert({-> assert_equal('3: å', term_getline(buf, 5))}) + call ch_sendraw(chan, "\xb2\n") + call WaitForAssert({-> assert_equal('3: å̲', term_getline(buf, 5))}) + call WaitForAssert({-> assert_equal('3: å̲', term_getline(buf, 6))}) + + exe buf .. "bwipe!" +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/version.c b/src/version.c index fea5c51edf..a9967e2bb5 100644 --- a/src/version.c +++ b/src/version.c @@ -734,6 +734,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 2134, /**/ 2133, /**/