Subject: bug#23159: 24.5; --eval bug

From: [email-masked]
Date: Sun, 03 Jul 2016 14:54:32 -0400

Devon Sean McCullough <[email-masked]> writes:

> I’d suggest (error "Trailing garbage following expression”)
> for consistency with the eval-expression function.

Makes sense.

>From 5990021e37069a8a03181dc5167f0e94d748981e Mon Sep 17 00:00:00 2001
From: Noam Postavsky <[email-masked]>
Date: Sat, 2 Jul 2016 20:26:35 -0400
Subject: [PATCH v2] Warn if --eval arg has text beyond 1 expression

* lisp/startup.el (command-line-1): If --eval argument has more data
than constitutes a single Lisp expression, print warning (Bug #23159).
---
 lisp/startup.el | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/lisp/startup.el b/lisp/startup.el
index 761e69e..75ae9f9 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -2360,7 +2360,15 @@ command-line-1
 
                     ((member argi '("-eval" "-execute"))
                      (setq inhibit-startup-screen t)
-                     (eval (read (or argval (pop command-line-args-left)))))
+                     (let* ((str-expr (or argval (pop command-line-args-left)))
+                            (read-data (read-from-string str-expr))
+                            (expr (car read-data))
+                            (end (cdr read-data)))
+                       (eval expr)
+                       (unless (= end (length str-expr))
+                         (lwarn '(command-line eval) :warning
+                                "Trailing garbage following expression: %s"
+                                (substring str-expr end)))))
 
                     ((member argi '("-L" "-directory"))
                      ;; -L :/foo adds /foo to the _end_ of load-path.
-- 
2.8.0