unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Spencer Baugh <sbaugh@janestreet.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 65902@debbugs.gnu.org, sbaugh@catern.com, jporterbugs@gmail.com
Subject: bug#65902: 29.0.92; emacsclient-mail.desktop fails due to complicated escaping
Date: Thu, 14 Sep 2023 10:04:48 -0400	[thread overview]
Message-ID: <iermsxoam0v.fsf@janestreet.com> (raw)
In-Reply-To: <83pm2klvw9.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 14 Sep 2023 16:36:06 +0300")

Eli Zaretskii <eliz@gnu.org> writes:

>> From: sbaugh@catern.com
>> Date: Thu, 14 Sep 2023 11:03:44 +0000 (UTC)
>> Cc: Jim Porter <jporterbugs@gmail.com>, 65902@debbugs.gnu.org,
>> 	sbaugh@janestreet.com
>> 
>> The issue is not really with the desktop file.  It's a generic problem:
>
> No, it isn't.  If it were, we'd have heard about it much sooner, and
> not because of the desktop files.
>
> What you are doing is representing a rare problem related to a niche
> feature is if it were a general one, by inventing use cases to justify
> that.  But if those use cases were important, people would have asked
> for them long ago.  They didn't.  Why? because --eval already exists.

No... these are real use cases that I personally have.  I have really
wanted this for a long time.  As I said in my original email, "I expect
this to also be useful in other places; the need to escape arbitrary
inputs before passing them to emacsclient is frequently annoying."

- I've wanted the ability to pass arbitrary data to Emacs through
  emacsclient since at least 2016, for other reasons:
  https://lists.gnu.org/archive/html/emacs-devel/2016-06/msg00051.html

- The fact that there is currently advice in org-protocol to implement
  this behavior means there are people who want it.  I'm sure the
  org-protocol authors really wanted to be able to avoid that advice,
  back when they developed it in 2009.  They didn't bother contributing
  a solution upstream back then, but why stop it from happening now?

- It would allow lazy loading of org-protocol as desired by the org devs
  https://list.orgmode.org/strc07$3o0$1@ciao.gmane.io

- I'm working on a package which allows using Emacs to do
  completing-read over arbitrary strings passed in from the command
  line, as a replacement for the popular terminal software fzf.  Since
  this is completion over arbitrary strings, I need the ability to get
  those arbitrary strings into Emacs.

- There are numerous examples on the web of users trying and failing to
  get the quoting right to pass arguments to emacsclient; for example

  https://www.reddit.com/r/emacs/comments/hhbcg7/emacsclient_eval_with_command_line_arguments/
  this would become
  emacsclient --apply switch-to-buffer

  https://stackoverflow.com/questions/8848819/emacs-eval-ediff-1-2-how-to-put-this-line-in-to-shell-script
  this would become
  emacsclient --apply ediff

  No shell complexities required in either case.

>> > What about alternative solutions: use a shell script in the desktop
>> > files, and delegate to that script to solve the problem with quoting?
>> > Had anyone considered this strategy?  If not, why not?
>> 
>> Getting the quoting right is hard and complex, and even Emacs developers
>> have failed at it over multiple iterations, and when they fail it either
>> breaks or exposes a security vulnerability.
>
> Emacs developers make mistakes even in the simple regexps we have in
> our code.  That doesn't mean we should abandon regexps.  The solution
> for sending Lisp forms to the server exists, and the quoting, although
> tricky in some cases, is not rocket science to get right.

I think this (the current contents of emacsclient-mail.desktop):
sh -c "u=\\$(echo \\"\\$1\\" | sed 's/[\\\\\\"]/\\\\\\\\&/g'); exec
emacsclient --alternate-editor= --display=\\"\\$DISPLAY\\" --eval
\\"(message-mailto \\\\\\"\\$u\\\\\\")\\"" sh %u

is in fact rocket science, and rocket science that needs to be repeated
by every user who wants to pass arbitrary strings to Emacs.

And keep in mind this mass of escaping *is currently broken*.

> I don't see
> why we would need another mechanism to do something similar with
> radically different syntax, a separate set of rules and restrictions
> that need to be documented, etc. etc.
>
>> This solution is far simpler
>
> That's an illusion.  There's nothing simple about it.  You are
> inventing a new mechanism for passing Lisp forms as something other
> than Lisp.

But I don't want to pass Lisp forms, that's the entire point.  I have
some arbitrary string which is *not* Lisp, and I want Emacs to *not*
parse it as Lisp.

> This has got to have issues into which we will bump sooner
> or later.  E.g., assume that two or more of the arguments to the
> function begins with single quote, as in
>
>   $ emacsclient --apply func arg1 'foo arg2 'bar
>
> Escape-quoting, here we come again!

That example works fine with --apply.  The call becomes:
(func "arg1" "'foo" "arg2" "'bar")
which is reliable and expected.

Maybe you're referring to how, if you run that command through a shell,
the shell interprets the single quotes as creating a string?  But that's
that's a separate issue, because:

- I don't plan to run any of my commands using --apply through a shell
  (which means they will require zero escaping or quoting whatsoever)

- Right now with --eval you have to do escaping for both the shell and
  Lisp.  With --apply you only have to do escaping for the shell, if you
  do use a shell, and if you don't use a shell you don't have to do
  anything.

I think it is simpler to reduce the amount of quoting and escaping from
"both Lisp and shell" to "just shell, and not even that if you don't use
a shell".





  reply	other threads:[~2023-09-14 14:04 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <fe2cc764-86c6-4840-80b7-8f3a3778b374@email.android.com>
2023-09-13 14:50 ` bug#65902: 29.0.92; emacsclient-mail.desktop fails due to complicated escaping Eli Zaretskii
2023-09-13 15:01   ` Andreas Schwab
2023-09-13 15:23   ` Spencer Baugh
2023-09-13 16:19     ` Jim Porter
2023-09-13 19:13     ` Eli Zaretskii
2023-09-13 19:33       ` Jim Porter
2023-09-13 20:00         ` Spencer Baugh
2023-09-13 20:16           ` Jim Porter
2023-09-14  5:10         ` Eli Zaretskii
2023-09-14 11:03           ` sbaugh
2023-09-14 11:18             ` sbaugh
2023-09-14 11:35             ` sbaugh
2023-09-14 13:36             ` Eli Zaretskii
2023-09-14 14:04               ` Spencer Baugh [this message]
2023-09-14 14:31                 ` Eli Zaretskii
2023-09-14 19:16               ` Jim Porter
2023-09-15  5:33                 ` Eli Zaretskii
2023-09-16 13:43           ` Björn Bidar via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-16 14:02             ` Eli Zaretskii
2023-09-16 15:54               ` Björn Bidar via Bug reports for GNU Emacs, the Swiss army knife of text editors
     [not found] <80d8aeb0-c9f1-410f-b83d-60f83ca5b3af@email.android.com>
2023-09-14 14:57 ` Eli Zaretskii
2023-09-14 15:10   ` Spencer Baugh
2023-09-15  6:29     ` Eli Zaretskii
2023-09-22  1:36       ` sbaugh
2023-09-22  6:36         ` Eli Zaretskii
2023-09-23 20:24           ` sbaugh
2023-09-24  5:18             ` Eli Zaretskii
2023-09-24 14:20               ` sbaugh
2023-10-21 15:20                 ` sbaugh
2023-10-22  5:27                   ` Eli Zaretskii
2023-10-22 14:15                     ` sbaugh
2023-10-22 16:09                       ` Andreas Schwab
2023-10-22 19:53                         ` sbaugh
2023-10-23 16:38                           ` Andreas Schwab
2023-10-23 16:52                           ` Jim Porter
2023-10-24 16:27                             ` sbaugh
2023-10-29 12:20                               ` Eli Zaretskii
2023-10-22  5:39                   ` Jim Porter
2023-09-22  7:05         ` Stefan Kangas
2023-09-22  7:14           ` Eli Zaretskii
2023-09-22  9:29             ` Andreas Schwab
2023-09-22 11:32               ` Eli Zaretskii
2023-09-22 12:37                 ` Andreas Schwab
2023-09-22 12:56                   ` Eli Zaretskii
2023-09-22 13:23                     ` Andreas Schwab
2023-09-22 14:51                       ` Eli Zaretskii
2023-09-22 14:52                         ` Andreas Schwab
2023-09-13  2:24 sbaugh
2023-09-13  2:30 ` sbaugh
2023-09-13  3:46   ` Jim Porter
2023-09-13  8:00     ` Robert Pluim
2023-09-13 13:06       ` Eli Zaretskii
2023-09-13 14:22         ` Robert Pluim
2023-09-13 12:41     ` Eli Zaretskii
2023-09-13 12:57     ` sbaugh
2023-09-13 12:41   ` Eli Zaretskii
2023-09-13 13:01     ` sbaugh
2023-09-13 13:26       ` Eli Zaretskii
2023-09-16 13:30         ` Björn Bidar via Bug reports for GNU Emacs, the Swiss army knife of text editors

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=iermsxoam0v.fsf@janestreet.com \
    --to=sbaugh@janestreet.com \
    --cc=65902@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=jporterbugs@gmail.com \
    --cc=sbaugh@catern.com \
    /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).