]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix term.el bug with very short multibyte character chunk
authorStephane Zermatten <szermatt@gmx.net>
Mon, 31 Mar 2025 13:41:08 +0000 (16:41 +0300)
committerEshel Yaron <me@eshelyaron.com>
Sun, 13 Apr 2025 20:54:24 +0000 (22:54 +0200)
Before this change, a chunk containing only a part
of a multibyte character would be discarded and
displayed undecoded on the terminal.
* lisp/term.el (term-emulate-terminal): Fix handling chunks
with part of a multibyte character.  (Bug#77410)

* test/lisp/term-tests.el (term-decode-partial)
(term-undecodable-input): Fix and enhance tests.

Copyright-paperwork-exempt: yes
(cherry picked from commit 158cf528c4aa690be84f9d1c3bc96b750e8b37b3)

lisp/term.el
test/lisp/term-tests.el

index fcbc1a421d165c377b3290781ea20e82c4dc5e0f..4a5850978d934549e1abf36471cfe4aac2ecaab8 100644 (file)
@@ -3112,7 +3112,7 @@ See `term-prompt-regexp'."
                                                           (- count 1 partial)))
                                       'eight-bit))
                         (incf partial))
-                      (when (> count partial 0)
+                      (when (> partial 0)
                         (setq term-terminal-undecoded-bytes
                               (substring decoded-substring (- partial)))
                         (setq decoded-substring
index 5ef8c1174dfb26ffc6f5a235e23de5f17326621f..ffb341f3b52b85588b1d2e439e69eac871044872 100644 (file)
@@ -402,17 +402,18 @@ This is a reduced example from GNU nano's initial screen."
 (ert-deftest term-decode-partial () ;; Bug#25288.
   "Test multibyte characters sent into multiple chunks."
   ;; Set `locale-coding-system' so test will be deterministic.
-  (let* ((locale-coding-system 'utf-8-unix)
-         (string (make-string 7 ?ш))
-         (bytes (encode-coding-string string locale-coding-system)))
-    (should (equal string
-                   (term-test-screen-from-input
-                    40 1 `(,(substring bytes 0 (/ (length bytes) 2))
-                           ,(substring bytes (/ (length bytes) 2))))))))
+  (let ((locale-coding-system 'utf-8-unix))
+    (should (equal "шшш" (term-test-screen-from-input
+                          40 1 '("\321" "\210\321\210\321\210"))))
+    (should (equal "шшш" (term-test-screen-from-input
+                          40 1 '("\321\210\321" "\210\321\210"))))
+    (should (equal "шшш" (term-test-screen-from-input
+                          40 1 '("\321\210\321\210\321" "\210"))))))
+
 (ert-deftest term-undecodable-input () ;; Bug#29918.
   "Undecodable bytes should be passed through without error."
   (let* ((locale-coding-system 'utf-8-unix) ; As above.
-         (bytes "\376\340\360\370")
+         (bytes "\376\340\360\370.")
          (string (decode-coding-string bytes locale-coding-system)))
     (should (equal string
                    (term-test-screen-from-input