unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#36219: GNU Emacs 26.1 --eval rejects trailing whitespace
@ 2019-06-15  2:39 �o�ӡ����Yһ��
  2019-06-15 13:33 ` Noam Postavsky
  0 siblings, 1 reply; 6+ messages in thread
From: �o�ӡ����Yһ�� @ 2019-06-15  2:39 UTC (permalink / raw)
  To: 36219

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="gb18030", Size: 2117 bytes --]

Since commit a90d5e6309c0306d931d398506b242c3eb4f40d7 which fixes bug #23159
the `--eval' command line option signals (error "Trailing garbage following
expression: %s") on more than one expression recevied.

===
$ Emacs --batch --eval "1 2"
Trailing garbage following expression:  2
===

However if there's trailing white space even single valid expression would be
rejected after the fix.

===
$ Emacs --batch --eval "1  "
Trailing garbage following expression:   
===

This causes some old shell script snippets which has trailing newline for
formatting no longer works, such as the follow script from
https://orgmode.org/manual/Batch-Execution.html#Batch-Execution

===
#!/bin/sh
# Tangle files with Org mode
#
emacs -Q --batch --eval "
    (progn
      (require 'ob-tangle)
      (dolist (file command-line-args-left)
        (with-current-buffer (find-file-noselect file)
          (org-babel-tangle))))
  " "$@"
===

From the proposal in bug#23159
https://lists.gnu.org/archive/html/bug-gnu-emacs/2016-07/msg00097.html

> I¡¯d suggest (error =22Trailing garbage following expression¡±)
> for consistency with the eval-expression function.
>
>                 Peace
>                         ¡ªDevon


Since `eval-expression' accepts additional white space and newlines after a
single expression, this mismatch behavior of `--eval' should be considered as a
bug.

My proposed fix is apply `string-trim-right` to received string of expression.

--- lisp/startup.el.old	2019-06-15 10:31:59.000000000 +0800
+++ lisp/startup.el	2019-06-15 10:34:51.000000000 +0800
@@ -2360,7 +2360,9 @@
 
                     ((member argi '("-eval" "-execute"))
                      (setq inhibit-startup-screen t)
-                     (let* ((str-expr (or argval (pop command-line-args-left)))
+                     (let* ((str-expr
+                             (string-trim-right
+                              (or argval (pop command-line-args-left))))
                             (read-data (read-from-string str-expr))
                             (expr (car read-data))
                             (end (cdr read-data)))

^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#36219: GNU Emacs 26.1 --eval rejects trailing whitespace
  2019-06-15  2:39 bug#36219: GNU Emacs 26.1 --eval rejects trailing whitespace �o�ӡ����Yһ��
@ 2019-06-15 13:33 ` Noam Postavsky
  2019-06-15 13:54   ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Noam Postavsky @ 2019-06-15 13:33 UTC (permalink / raw)
  To: andpuke; +Cc: 36219

[-- Attachment #1: Type: text/plain, Size: 874 bytes --]

severity 36219 minor
tags 36219 + patch
quit

<andpuke@foxmail.com> writes:

> Since commit a90d5e6309c0306d931d398506b242c3eb4f40d7 which fixes bug #23159
> the `--eval' command line option signals (error "Trailing garbage following
> expression: %s") on more than one expression recevied.

> This causes some old shell script snippets which has trailing newline for
> formatting no longer works, such as the follow script from
> https://orgmode.org/manual/Batch-Execution.html#Batch-Execution


> Since `eval-expression' accepts additional white space and newlines after a
> single expression, this mismatch behavior of `--eval' should be considered as a
> bug.
>
> My proposed fix is apply `string-trim-right` to received string of expression.
>

I think I'd prefer checking the trailing garbage for whitespace, which
is what eval-expression does.  See following patch:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 1220 bytes --]

From c067e710eb7d6e1606f0cdd76e37fe84104d33d8 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Sat, 15 Jun 2019 08:40:23 -0400
Subject: [PATCH] Allow trailing whitespace in --eval argument (Bug#36219)

* lisp/startup.el (command-line-1): Don't complain about trailing
garbage if it's only space, tab, or newline characters.
---
 lisp/startup.el | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lisp/startup.el b/lisp/startup.el
index 32051c232c..f5463f2c93 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -2376,7 +2376,9 @@ (defun command-line-1 (args-left)
                             (read-data (read-from-string str-expr))
                             (expr (car read-data))
                             (end (cdr read-data)))
-                       (unless (= end (length str-expr))
+                       ;; Allow same trailing chars as minibuf.c's
+                       ;; `string_to_object'.
+                       (unless (string-match-p "[\s\t\n]*\\'" str-expr end)
                          (error "Trailing garbage following expression: %s"
                                 (substring str-expr end)))
                        (eval expr)))
-- 
2.11.0


[-- Attachment #3: Type: text/plain, Size: 144 bytes --]


This is a regression from Emacs 25, and the fix looks pretty safe to me;
although the bug isn't especially severe.  Should it go to emacs-26?


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* bug#36219: GNU Emacs 26.1 --eval rejects trailing whitespace
  2019-06-15 13:33 ` Noam Postavsky
@ 2019-06-15 13:54   ` Eli Zaretskii
  2019-06-15 14:06     ` Noam Postavsky
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2019-06-15 13:54 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: andpuke, 36219

> From: Noam Postavsky <npostavs@gmail.com>
> Date: Sat, 15 Jun 2019 09:33:10 -0400
> Cc: 36219@debbugs.gnu.org
> 
> <andpuke@foxmail.com> writes:
> 
> > Since commit a90d5e6309c0306d931d398506b242c3eb4f40d7 which fixes bug #23159
> > the `--eval' command line option signals (error "Trailing garbage following
> > expression: %s") on more than one expression recevied.
> 
> > This causes some old shell script snippets which has trailing newline for
> > formatting no longer works, such as the follow script from
> > https://orgmode.org/manual/Batch-Execution.html#Batch-Execution
> 
> 
> > Since `eval-expression' accepts additional white space and newlines after a
> > single expression, this mismatch behavior of `--eval' should be considered as a
> > bug.
> >
> > My proposed fix is apply `string-trim-right` to received string of expression.
> >
> 
> I think I'd prefer checking the trailing garbage for whitespace, which
> is what eval-expression does.  See following patch:

SGTM, thanks.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#36219: GNU Emacs 26.1 --eval rejects trailing whitespace
  2019-06-15 13:54   ` Eli Zaretskii
@ 2019-06-15 14:06     ` Noam Postavsky
  2019-06-15 14:24       ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Noam Postavsky @ 2019-06-15 14:06 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: andpuke, 36219

Eli Zaretskii <eliz@gnu.org> writes:

>> I think I'd prefer checking the trailing garbage for whitespace, which
>> is what eval-expression does.  See following patch:
>
> SGTM, thanks.

Not sure if you missed my question about emacs-26 (it was below the
patch, maybe a bad place to put it)

    This is a regression from Emacs 25, and the fix looks pretty safe to me;
    although the bug isn't especially severe.  Should it go to emacs-26?





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#36219: GNU Emacs 26.1 --eval rejects trailing whitespace
  2019-06-15 14:06     ` Noam Postavsky
@ 2019-06-15 14:24       ` Eli Zaretskii
  2019-06-15 21:46         ` Noam Postavsky
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2019-06-15 14:24 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: andpuke, 36219

> From: Noam Postavsky <npostavs@gmail.com>
> Cc: andpuke@foxmail.com,  36219@debbugs.gnu.org
> Date: Sat, 15 Jun 2019 10:06:22 -0400
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> I think I'd prefer checking the trailing garbage for whitespace, which
> >> is what eval-expression does.  See following patch:
> >
> > SGTM, thanks.
> 
> Not sure if you missed my question about emacs-26 (it was below the
> patch, maybe a bad place to put it)
> 
>     This is a regression from Emacs 25, and the fix looks pretty safe to me;
>     although the bug isn't especially severe.  Should it go to emacs-26?

I think the fix should go to master.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#36219: GNU Emacs 26.1 --eval rejects trailing whitespace
  2019-06-15 14:24       ` Eli Zaretskii
@ 2019-06-15 21:46         ` Noam Postavsky
  0 siblings, 0 replies; 6+ messages in thread
From: Noam Postavsky @ 2019-06-15 21:46 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: andpuke, 36219

tags 36219 fixed
close 36219 27.1
quit

Eli Zaretskii <eliz@gnu.org> writes:
> I think the fix should go to master.

Okay, pushed to master.

a1b230b58a 2019-06-15T17:05:56-04:00 "Allow trailing whitespace in --eval argument (Bug#36219)"
https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=a1b230b58a4176a574bcb37573c82d1ccc71633c






^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-06-15 21:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-15  2:39 bug#36219: GNU Emacs 26.1 --eval rejects trailing whitespace �o�ӡ����Yһ��
2019-06-15 13:33 ` Noam Postavsky
2019-06-15 13:54   ` Eli Zaretskii
2019-06-15 14:06     ` Noam Postavsky
2019-06-15 14:24       ` Eli Zaretskii
2019-06-15 21:46         ` Noam Postavsky

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).