emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Max Nikulin <manikulin@gmail.com>
To: Xi Lu <lx@shellcodes.org>, emacs-orgmode@gnu.org
Subject: Re: [PATCH] Fix `grep' command to handle filenames starting with '-'.
Date: Fri, 8 Nov 2024 10:46:43 +0700	[thread overview]
Message-ID: <e2ee0750-161b-4706-9dbf-1c278aeccbb9@gmail.com> (raw)
In-Reply-To: <tencent_6F6A1EEF62E567C2C782CD384966126A0009@qq.com>

On 07/11/2024 16:24, Xi Lu wrote:
> +++ b/lisp/org-mouse.el
> @@ -627,7 +627,7 @@ This means, between the beginning of line and the point."
>   	   ["Sparse Tree" (org-occur ',region-string)]
>   	   ["Find in Buffer" (occur ',region-string)]
>   	   ["Grep in Current Dir"
> -	    (grep (format "grep -rnH -e '%s' *" ',region-string))]
> +	    (grep (format "grep -rnH -e '%s' ./*" ',region-string))]

Thanks, I find it as an acceptable quick fix despite it adds noisy "./" 
to file names that are not started with "-". In BASH it is possible to 
do something like

     shopt -s nullglob; echo ./-* [!-]*

but it is not portable (and portable [!CHAR] negation may be treated as 
history expansion by some *interactive* shells).

Xi Lu, is it a kind of friendly trolling that you submitted a patch with 
a workaround for leading dash file name pitfall, but you decided to keep 
ability to pass arbitrary shell code as selection? Just quotes is a poor 
way to protect against shell specials and it can be easily bypassed.

P.S. This code needs some love. I would expect `grep-command' or 
`grep-find-command' variable should be respected here. There are grep 
alternatives that respect VCS ignore files and thus work much faster. 
However it is for another patch, not for this thread.

I am in doubts if "-F" should be added. Literal search for *selected* 
text is more reasonable from my point of view.

     grep -rnH -e '[aa' ./*
     grep: Unmatched [, [^, [:, [., or [=

P.P.S. Some links for the context of leading dash issues:
- <https://www.shellcheck.net/wiki/SC2035>
   "Use ./*glob* or -- *glob* so names with dashes won't become options."
- <https://www.openwall.com/lists/oss-security/2024/11/06/1>
   "shell wildcard expansion (un)safety" Wed, 6 Nov 2024 05:12:15 +0100
- <https://mywiki.wooledge.org/BashPitfalls#pf3>
   3. Filenames with leading dashes



  parent reply	other threads:[~2024-11-08  4:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-07  9:24 [PATCH] Fix `grep' command to handle filenames starting with '-' Xi Lu
2024-11-07 10:40 ` Rens Oliemans
2024-11-07 10:44   ` lux
2024-11-08  3:46 ` Max Nikulin [this message]
2024-11-08  3:56   ` lux
2024-11-09 14:35 ` Ihor Radchenko

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.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e2ee0750-161b-4706-9dbf-1c278aeccbb9@gmail.com \
    --to=manikulin@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=lx@shellcodes.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/org-mode.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).