emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs-26 150bdfe: Handle completely undecoded input in ter


From: Noam Postavsky
Subject: [Emacs-diffs] emacs-26 150bdfe: Handle completely undecoded input in term (Bug#29918)
Date: Sat, 20 Jul 2019 22:31:01 -0400 (EDT)

branch: emacs-26
commit 150bdfe43acde8423612cbff4eafbbb88878b497
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>

    Handle completely undecoded input in term (Bug#29918)
    
    * lisp/term.el (term-emulate-terminal): Avoid errors if the whole
    decoded string is eight-bit characters.  Don't attempt to save the
    string for next iteration in that case.
    * test/lisp/term-tests.el (term-decode-partial)
    (term-undecodable-input): New tests.
---
 lisp/term.el            |  9 +++++----
 test/lisp/term-tests.el | 19 +++++++++++++++++++
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/lisp/term.el b/lisp/term.el
index cbef68d..9785ce3 100644
--- a/lisp/term.el
+++ b/lisp/term.el
@@ -2900,11 +2900,12 @@ See `term-prompt-regexp'."
                           ;; next time.
                           (when (= funny str-length)
                             (let ((partial 0))
-                              (while (eq (char-charset (aref decoded-substring
-                                                             (- count 1 
partial)))
-                                         'eight-bit)
+                              (while (and (< partial count)
+                                          (eq (char-charset (aref 
decoded-substring
+                                                                  (- count 1 
partial)))
+                                              'eight-bit))
                                 (cl-incf partial))
-                              (when (> partial 0)
+                              (when (> count partial 0)
                                 (setq term-terminal-undecoded-bytes
                                       (substring decoded-substring (- 
partial)))
                                 (setq decoded-substring
diff --git a/test/lisp/term-tests.el b/test/lisp/term-tests.el
index c2b90dea..237e19d 100644
--- a/test/lisp/term-tests.el
+++ b/test/lisp/term-tests.el
@@ -144,6 +144,25 @@ This is a reduced example from GNU nano's initial screen."
                     `("\e[1;3r" "\e[2;1H" ,x "\r\e[1A" ,y))
                    (concat y "\n" x)))))
 
+(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))))))))
+
+(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")
+         (string (decode-coding-string bytes locale-coding-system)))
+    (should (equal string
+                   (term-test-screen-from-input
+                    40 1 bytes)))))
 
 (provide 'term-tests)
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]