diff options
| author | Noam Postavsky | 2017-06-07 19:59:09 -0400 |
|---|---|---|
| committer | Noam Postavsky | 2017-07-22 08:47:31 -0400 |
| commit | 8b18911a5c7c6c8a15b3cff12a4376ba68205e1c (patch) | |
| tree | 87354ab39568fb3162761b578bbdd70035e3b727 | |
| parent | 37954f39168e0dbfe3a82feb9b58fecfc5f1f318 (diff) | |
| download | emacs-8b18911a5c7c6c8a15b3cff12a4376ba68205e1c.tar.gz emacs-8b18911a5c7c6c8a15b3cff12a4376ba68205e1c.zip | |
Signal error for symbol names with strange quotes (Bug#2967)
* src/lread.c (read1): Signal an error when a symbol starts with a
non-escaped quote-like character.
* test/src/lread-tests.el (lread-tests--funny-quote-symbols): New
test.
* etc/NEWS: Announce change.
| -rw-r--r-- | etc/NEWS | 4 | ||||
| -rw-r--r-- | src/lread.c | 18 | ||||
| -rw-r--r-- | test/src/lread-tests.el | 17 |
3 files changed, 39 insertions, 0 deletions
| @@ -1154,6 +1154,10 @@ instead of its first. | |||
| 1154 | renamed to 'lread--old-style-backquotes'. No user code should use | 1154 | renamed to 'lread--old-style-backquotes'. No user code should use |
| 1155 | this variable. | 1155 | this variable. |
| 1156 | 1156 | ||
| 1157 | ** To avoid confusion caused by "smart quotes", the reader no longer | ||
| 1158 | accepts Lisp symbols which begin with the following quotation | ||
| 1159 | characters: ‘’‛“”‟〞"', unless they are escaped with backslash. | ||
| 1160 | |||
| 1157 | +++ | 1161 | +++ |
| 1158 | ** Module functions are now implemented slightly differently; in | 1162 | ** Module functions are now implemented slightly differently; in |
| 1159 | particular, the function 'internal--module-call' has been removed. | 1163 | particular, the function 'internal--module-call' has been removed. |
diff --git a/src/lread.c b/src/lread.c index 901e40b3489..dbaadce4b40 100644 --- a/src/lread.c +++ b/src/lread.c | |||
| @@ -3479,6 +3479,24 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list) | |||
| 3479 | if (! NILP (result)) | 3479 | if (! NILP (result)) |
| 3480 | return unbind_to (count, result); | 3480 | return unbind_to (count, result); |
| 3481 | } | 3481 | } |
| 3482 | if (!quoted && multibyte) | ||
| 3483 | { | ||
| 3484 | int ch = STRING_CHAR ((unsigned char *) read_buffer); | ||
| 3485 | switch (ch) | ||
| 3486 | { | ||
| 3487 | case 0x2018: /* LEFT SINGLE QUOTATION MARK */ | ||
| 3488 | case 0x2019: /* RIGHT SINGLE QUOTATION MARK */ | ||
| 3489 | case 0x201B: /* SINGLE HIGH-REVERSED-9 QUOTATION MARK */ | ||
| 3490 | case 0x201C: /* LEFT DOUBLE QUOTATION MARK */ | ||
| 3491 | case 0x201D: /* RIGHT DOUBLE QUOTATION MARK */ | ||
| 3492 | case 0x201F: /* DOUBLE HIGH-REVERSED-9 QUOTATION MARK */ | ||
| 3493 | case 0x301E: /* DOUBLE PRIME QUOTATION MARK */ | ||
| 3494 | case 0xFF02: /* FULLWIDTH QUOTATION MARK */ | ||
| 3495 | case 0xFF07: /* FULLWIDTH APOSTROPHE */ | ||
| 3496 | xsignal2 (Qinvalid_read_syntax, build_string ("strange quote"), | ||
| 3497 | CALLN (Fstring, make_number (ch))); | ||
| 3498 | } | ||
| 3499 | } | ||
| 3482 | { | 3500 | { |
| 3483 | Lisp_Object result; | 3501 | Lisp_Object result; |
| 3484 | ptrdiff_t nbytes = p - read_buffer; | 3502 | ptrdiff_t nbytes = p - read_buffer; |
diff --git a/test/src/lread-tests.el b/test/src/lread-tests.el index a0a317feeeb..dd5a2003b41 100644 --- a/test/src/lread-tests.el +++ b/test/src/lread-tests.el | |||
| @@ -142,6 +142,23 @@ literals (Bug#20852)." | |||
| 142 | "unescaped character literals " | 142 | "unescaped character literals " |
| 143 | "`?\"', `?(', `?)', `?;', `?[', `?]' detected!"))))) | 143 | "`?\"', `?(', `?)', `?;', `?[', `?]' detected!"))))) |
| 144 | 144 | ||
| 145 | (ert-deftest lread-tests--funny-quote-symbols () | ||
| 146 | "Check that 'smart quotes' or similar trigger errors in symbol names." | ||
| 147 | (dolist (quote-char | ||
| 148 | '(#x2018 ;; LEFT SINGLE QUOTATION MARK | ||
| 149 | #x2019 ;; RIGHT SINGLE QUOTATION MARK | ||
| 150 | #x201B ;; SINGLE HIGH-REVERSED-9 QUOTATION MARK | ||
| 151 | #x201C ;; LEFT DOUBLE QUOTATION MARK | ||
| 152 | #x201D ;; RIGHT DOUBLE QUOTATION MARK | ||
| 153 | #x201F ;; DOUBLE HIGH-REVERSED-9 QUOTATION MARK | ||
| 154 | #x301E ;; DOUBLE PRIME QUOTATION MARK | ||
| 155 | #xFF02 ;; FULLWIDTH QUOTATION MARK | ||
| 156 | #xFF07 ;; FULLWIDTH APOSTROPHE | ||
| 157 | )) | ||
| 158 | (let ((str (format "%cfoo" quote-char))) | ||
| 159 | (should-error (read str) :type 'invalid-read-syntax) | ||
| 160 | (should (eq (read (concat "\\" str)) (intern str)))))) | ||
| 161 | |||
| 145 | (ert-deftest lread-test-bug26837 () | 162 | (ert-deftest lread-test-bug26837 () |
| 146 | "Test for http://debbugs.gnu.org/26837 ." | 163 | "Test for http://debbugs.gnu.org/26837 ." |
| 147 | (let ((load-path (cons | 164 | (let ((load-path (cons |