From: npostavs@users.sourceforge.net
To: Eli Zaretskii <eliz@gnu.org>
Cc: 2967@debbugs.gnu.org, monnier@iro.umontreal.ca, acm@muc.de
Subject: bug#2967: smart quotes in .emacs
Date: Sun, 16 Jul 2017 20:49:39 -0400 [thread overview]
Message-ID: <87shhvc2fw.fsf@users.sourceforge.net> (raw)
In-Reply-To: <83vao88jud.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 07 Jun 2017 08:09:30 +0300")
[-- Attachment #1: Type: text/plain, Size: 426 bytes --]
tags 2967 + patch
quit
Eli Zaretskii <eliz@gnu.org> writes:
> Please include the character itself in the error message text.
>
> Also, are we sure these two are the only ones we want to catch in this
> manner?
I added some more likely looking ones from
https://en.wikipedia.org/wiki/Quotation_mark_glyphs.
> Finally, if this is accepted, let's have a test for this, and maybe
> also some documentation, at least in NEWS.
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 3825 bytes --]
From 438030f42698f347e38a9dea1561eedadd7e2edc Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Wed, 7 Jun 2017 19:59:09 -0400
Subject: [PATCH v2] 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.
---
etc/NEWS | 4 ++++
src/lread.c | 18 ++++++++++++++++++
test/src/lread-tests.el | 17 +++++++++++++++++
3 files changed, 39 insertions(+)
diff --git a/etc/NEWS b/etc/NEWS
index edb71118ef..d297d049d1 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1110,6 +1110,10 @@ instead of its first.
renamed to 'lread--old-style-backquotes'. No user code should use
this variable.
+** To avoid confusion caused by "smart quotes", the reader no longer
+accepts Lisp symbols which begin with the following quotation
+characters: ‘’‛“”‟〞"', unless they are escaped with backslash.
+
+++
** Module functions are now implemented slightly differently; in
particular, the function 'internal--module-call' has been removed.
diff --git a/src/lread.c b/src/lread.c
index 901e40b348..dbaadce4b4 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -3479,6 +3479,24 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list)
if (! NILP (result))
return unbind_to (count, result);
}
+ if (!quoted && multibyte)
+ {
+ int ch = STRING_CHAR ((unsigned char *) read_buffer);
+ switch (ch)
+ {
+ case 0x2018: /* LEFT SINGLE QUOTATION MARK */
+ case 0x2019: /* RIGHT SINGLE QUOTATION MARK */
+ case 0x201B: /* SINGLE HIGH-REVERSED-9 QUOTATION MARK */
+ case 0x201C: /* LEFT DOUBLE QUOTATION MARK */
+ case 0x201D: /* RIGHT DOUBLE QUOTATION MARK */
+ case 0x201F: /* DOUBLE HIGH-REVERSED-9 QUOTATION MARK */
+ case 0x301E: /* DOUBLE PRIME QUOTATION MARK */
+ case 0xFF02: /* FULLWIDTH QUOTATION MARK */
+ case 0xFF07: /* FULLWIDTH APOSTROPHE */
+ xsignal2 (Qinvalid_read_syntax, build_string ("strange quote"),
+ CALLN (Fstring, make_number (ch)));
+ }
+ }
{
Lisp_Object result;
ptrdiff_t nbytes = p - read_buffer;
diff --git a/test/src/lread-tests.el b/test/src/lread-tests.el
index a0a317feee..dd5a2003b4 100644
--- a/test/src/lread-tests.el
+++ b/test/src/lread-tests.el
@@ -142,6 +142,23 @@ (ert-deftest lread-tests--unescaped-char-literals ()
"unescaped character literals "
"`?\"', `?(', `?)', `?;', `?[', `?]' detected!")))))
+(ert-deftest lread-tests--funny-quote-symbols ()
+ "Check that 'smart quotes' or similar trigger errors in symbol names."
+ (dolist (quote-char
+ '(#x2018 ;; LEFT SINGLE QUOTATION MARK
+ #x2019 ;; RIGHT SINGLE QUOTATION MARK
+ #x201B ;; SINGLE HIGH-REVERSED-9 QUOTATION MARK
+ #x201C ;; LEFT DOUBLE QUOTATION MARK
+ #x201D ;; RIGHT DOUBLE QUOTATION MARK
+ #x201F ;; DOUBLE HIGH-REVERSED-9 QUOTATION MARK
+ #x301E ;; DOUBLE PRIME QUOTATION MARK
+ #xFF02 ;; FULLWIDTH QUOTATION MARK
+ #xFF07 ;; FULLWIDTH APOSTROPHE
+ ))
+ (let ((str (format "%cfoo" quote-char)))
+ (should-error (read str) :type 'invalid-read-syntax)
+ (should (eq (read (concat "\\" str)) (intern str))))))
+
(ert-deftest lread-test-bug26837 ()
"Test for http://debbugs.gnu.org/26837 ."
(let ((load-path (cons
--
2.11.1
next prev parent reply other threads:[~2017-07-17 0:49 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-12 12:53 bug#2967: smart quotes in .emacs Kit O'Connell
2009-04-13 12:23 ` Stefan Monnier
2012-08-10 19:59 ` Glenn Morris
2017-06-07 3:46 ` npostavs
2017-06-07 5:09 ` Eli Zaretskii
2017-07-17 0:49 ` npostavs [this message]
2017-07-22 9:20 ` Eli Zaretskii
2017-07-22 14:41 ` npostavs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87shhvc2fw.fsf@users.sourceforge.net \
--to=npostavs@users.sourceforge.net \
--cc=2967@debbugs.gnu.org \
--cc=acm@muc.de \
--cc=eliz@gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).