From: Mattias EngdegÄrd Date: Fri, 3 Jun 2022 08:12:24 +0000 (+0200) Subject: Let ?\LF signal an error (bug#55738) X-Git-Tag: emacs-29.0.90~1910^2~265 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=28622d4dd0347227a28b7b25c674437239a00a06;p=emacs.git Let ?\LF signal an error (bug#55738) As suggested by Stefan Monnier. * src/lread.c (read_escape): Signal an error for ?\LF since it cannot reasonably be intended. * test/src/lread-tests.el (lread-escaped-lf): Update test. * etc/NEWS: Announce. --- diff --git a/etc/NEWS b/etc/NEWS index f9409bb24f8..54bc6d80e1a 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1922,6 +1922,9 @@ It was previously only run by 'clone-indirect-buffer' and called by both of these, the hook is now run by all 3 of these functions. +--- +** '?\' at the end of a line now signals an error. +Previously it produced a nonsense value, -1, that was never intended. * Lisp Changes in Emacs 29.1 diff --git a/src/lread.c b/src/lread.c index 4b7d38a8e6c..1d20470a8bf 100644 --- a/src/lread.c +++ b/src/lread.c @@ -2664,6 +2664,10 @@ read_escape (Lisp_Object readcharfun) case 'v': return '\v'; + case '\n': + /* ?\LF is an error; it's probably a user mistake. */ + error ("Invalid escape character syntax"); + case 'M': c = READCHAR; if (c != '-') diff --git a/test/src/lread-tests.el b/test/src/lread-tests.el index 99eec9d5487..f190f14781e 100644 --- a/test/src/lread-tests.el +++ b/test/src/lread-tests.el @@ -318,8 +318,8 @@ literals (Bug#20852)." '(## . 2)))) (ert-deftest lread-escaped-lf () - ;; ?\LF should produce LF (only inside string literals do we ignore \LF). - (should (equal (read-from-string "?\\\n") '(?\n . 3))) + ;; ?\LF should signal an error; \LF is ignored inside string literals. + (should-error (read-from-string "?\\\n x")) (should (equal (read-from-string "\"a\\\nb\"") '("ab" . 6)))) ;;; lread-tests.el ends here