unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Robert Pluim <rpluim@gmail.com>
To: Angus Lees <gus@inodes.org>
Cc: 29303@debbugs.gnu.org
Subject: bug#29303: 25.2; vc-git-grep should shell-escape FILES
Date: Wed, 15 Nov 2017 10:58:19 +0100	[thread overview]
Message-ID: <87efoz983o.fsf@gmail.com> (raw)
In-Reply-To: <CAPA_H3c3hZFBbsnQHveV7W70X4uEew_9Qy-5hFsYE3q4Yt_pGg@mail.gmail.com> (Angus Lees's message of "Wed, 15 Nov 2017 06:25:04 +0000")

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

Angus Lees <gus@inodes.org> writes:

> "git grep" is recursive.  Consequently, the globbing for FILES arg needs
> to be done *inside* git, and not by the shell invoking git.
>
> Specifically: `vc-git-grep` needs to shell-escape the FILES value after
> `grep-read-files` (so `grep-files-aliases` continues to work) and before
> calling `grep-expand-template` (which does no escaping itself).
>

You mean something like the patch below? I considered splitting on
spaces and doing shell-quote-argument, but that seems like overkill.

(this is where someone points me at a function somewhere in emacs that
does exactly this operation already)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Quote-filenames-to-inhibit-expansion-by-the-shell.patch --]
[-- Type: text/x-diff, Size: 954 bytes --]

From 788126ca723ba2e37553eaf5f17141be3544a5cb Mon Sep 17 00:00:00 2001
From: Robert Pluim <rpluim@gmail.com>
Date: Wed, 15 Nov 2017 10:51:37 +0100
Subject: [PATCH] Quote filenames to inhibit expansion by the shell

* lisp/vc/vc-git.el (vc-git-grep): Add quotes around filename patterns
to ensure globbing is done by git rather than the shell. (Bug#29303)
---
 lisp/vc/vc-git.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index ed85603f82..fd5f5d5b63 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -1428,7 +1428,8 @@ vc-git-grep
 				   nil nil 'grep-history)
 	     nil))
       (t (let* ((regexp (grep-read-regexp))
-		(files (grep-read-files regexp))
+		(files (concat "'" (replace-regexp-in-string " " "' '"
+				   (grep-read-files regexp)) "'"))
 		(dir (read-directory-name "In directory: "
 					  nil default-directory t)))
 	   (list regexp files dir))))))
-- 
2.15.0


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


Robert

  reply	other threads:[~2017-11-15  9:58 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-15  6:25 bug#29303: 25.2; vc-git-grep should shell-escape FILES Angus Lees
2017-11-15  9:58 ` Robert Pluim [this message]
2017-11-15 17:42   ` Eli Zaretskii
2017-11-15 18:45     ` Robert Pluim
2017-11-15 19:58       ` Eli Zaretskii
2017-11-15 20:17         ` Robert Pluim
2017-11-15 20:26           ` Eli Zaretskii
2017-11-15 20:36             ` Robert Pluim
2017-11-16 15:38               ` Eli Zaretskii
2017-11-16 15:43                 ` Robert Pluim
2017-11-17  7:13                   ` Angus Lees
2017-11-17  8:38                 ` Robert Pluim
2017-11-17  9:06                   ` Eli Zaretskii
2017-11-17  9:54                     ` Robert Pluim
2017-11-17 10:13                       ` Eli Zaretskii
2017-11-17 10:33                         ` Robert Pluim
2017-11-17 13:41                           ` Eli Zaretskii
2017-11-17 14:21                             ` Robert Pluim
2017-11-28 13:37                               ` Robert Pluim
2017-11-28 17:49                                 ` Eli Zaretskii
2017-11-16 15:55         ` Andreas Schwab

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=87efoz983o.fsf@gmail.com \
    --to=rpluim@gmail.com \
    --cc=29303@debbugs.gnu.org \
    --cc=gus@inodes.org \
    /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).