diff options
| author | Noam Postavsky | 2019-07-17 07:20:20 -0400 |
|---|---|---|
| committer | Noam Postavsky | 2019-07-20 21:35:21 -0400 |
| commit | 150bdfe43acde8423612cbff4eafbbb88878b497 (patch) | |
| tree | cde38dfb7a9bb330cb718ebd893876e7b15f8c7c | |
| parent | 021f32cca1b9082e7219b06aee28c00c4323a72a (diff) | |
| download | emacs-150bdfe43acde8423612cbff4eafbbb88878b497.tar.gz emacs-150bdfe43acde8423612cbff4eafbbb88878b497.zip | |
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.
| -rw-r--r-- | lisp/term.el | 9 | ||||
| -rw-r--r-- | test/lisp/term-tests.el | 19 |
2 files changed, 24 insertions, 4 deletions
diff --git a/lisp/term.el b/lisp/term.el index cbef68dc0ac..9785ce30249 100644 --- a/lisp/term.el +++ b/lisp/term.el | |||
| @@ -2900,11 +2900,12 @@ See `term-prompt-regexp'." | |||
| 2900 | ;; next time. | 2900 | ;; next time. |
| 2901 | (when (= funny str-length) | 2901 | (when (= funny str-length) |
| 2902 | (let ((partial 0)) | 2902 | (let ((partial 0)) |
| 2903 | (while (eq (char-charset (aref decoded-substring | 2903 | (while (and (< partial count) |
| 2904 | (- count 1 partial))) | 2904 | (eq (char-charset (aref decoded-substring |
| 2905 | 'eight-bit) | 2905 | (- count 1 partial))) |
| 2906 | 'eight-bit)) | ||
| 2906 | (cl-incf partial)) | 2907 | (cl-incf partial)) |
| 2907 | (when (> partial 0) | 2908 | (when (> count partial 0) |
| 2908 | (setq term-terminal-undecoded-bytes | 2909 | (setq term-terminal-undecoded-bytes |
| 2909 | (substring decoded-substring (- partial))) | 2910 | (substring decoded-substring (- partial))) |
| 2910 | (setq decoded-substring | 2911 | (setq decoded-substring |
diff --git a/test/lisp/term-tests.el b/test/lisp/term-tests.el index c2b90dea604..237e19d6b15 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." | |||
| 144 | `("\e[1;3r" "\e[2;1H" ,x "\r\e[1A" ,y)) | 144 | `("\e[1;3r" "\e[2;1H" ,x "\r\e[1A" ,y)) |
| 145 | (concat y "\n" x))))) | 145 | (concat y "\n" x))))) |
| 146 | 146 | ||
| 147 | (ert-deftest term-decode-partial () ;; Bug#25288. | ||
| 148 | "Test multibyte characters sent into multiple chunks." | ||
| 149 | ;; Set `locale-coding-system' so test will be deterministic. | ||
| 150 | (let* ((locale-coding-system 'utf-8-unix) | ||
| 151 | (string (make-string 7 ?ш)) | ||
| 152 | (bytes (encode-coding-string string locale-coding-system))) | ||
| 153 | (should (equal string | ||
| 154 | (term-test-screen-from-input | ||
| 155 | 40 1 `(,(substring bytes 0 (/ (length bytes) 2)) | ||
| 156 | ,(substring bytes (/ (length bytes) 2)))))))) | ||
| 157 | |||
| 158 | (ert-deftest term-undecodable-input () ;; Bug#29918. | ||
| 159 | "Undecodable bytes should be passed through without error." | ||
| 160 | (let* ((locale-coding-system 'utf-8-unix) ; As above. | ||
| 161 | (bytes "\376\340\360\370") | ||
| 162 | (string (decode-coding-string bytes locale-coding-system))) | ||
| 163 | (should (equal string | ||
| 164 | (term-test-screen-from-input | ||
| 165 | 40 1 bytes))))) | ||
| 147 | 166 | ||
| 148 | (provide 'term-tests) | 167 | (provide 'term-tests) |
| 149 | 168 | ||