mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-06-14 12:31:25 +00:00
Avoid crash in self-insert-command with non-ASCII auto-fill
* src/cmds.c (internal_self_insert): If the autofill function changed the newline character we inserted, don't attempt to restore point. * test/src/cmds-tests.el (self-insert-nonascii-autofill): New.
This commit is contained in:
parent
7f8ac8bf6f
commit
b72dcebdab
2 changed files with 18 additions and 1 deletions
|
|
@ -489,7 +489,7 @@ internal_self_insert (int c, EMACS_INT n)
|
|||
SET_PT_BOTH (PT - 1, PT_BYTE - 1);
|
||||
auto_fill_result = call0 (Qinternal_auto_fill);
|
||||
/* Test PT < ZV in case the auto-fill-function is strange. */
|
||||
if (c == '\n' && PT < ZV)
|
||||
if (c == '\n' && PT < ZV && FETCH_BYTE (PT) == '\n')
|
||||
SET_PT_BOTH (PT + 1, PT_BYTE + 1);
|
||||
if (!NILP (auto_fill_result))
|
||||
hairy = 2;
|
||||
|
|
|
|||
|
|
@ -48,5 +48,22 @@
|
|||
(self-insert-command 0 10)
|
||||
(should-not (equal pt 0)))))
|
||||
|
||||
(ert-deftest self-insert-nonascii-autofill ()
|
||||
"Test `self-insert-command' with a non-ASCII autofill function."
|
||||
(with-temp-buffer
|
||||
(let ((auto-fill-function
|
||||
(lambda ()
|
||||
(delete-char 1)
|
||||
(insert #x2000)
|
||||
(forward-char -1))))
|
||||
(dotimes (_ 10)
|
||||
(self-insert-command 1 10)
|
||||
(goto-char 2)
|
||||
(should (equal (point) 2))
|
||||
(should (equal (length (buffer-string)) 1))
|
||||
(should (equal (format "%S" (buffer-string))
|
||||
"\"\x2000\""))
|
||||
(delete-char -1)))))
|
||||
|
||||
(provide 'cmds-tests)
|
||||
;;; cmds-tests.el ends here
|
||||
|
|
|
|||
Loading…
Reference in a new issue