zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Johan Grande <nahoj@crans.org>
Cc: zsh-workers@zsh.org
Subject: Re: [bug] Completion functions _files/_path_files -F filter on escaped file names
Date: Wed, 21 Jun 2023 20:54:42 -0700	[thread overview]
Message-ID: <CAH+w=7Z4Ud0RxmzAaF6YZusxTVbSVD_feQiw8DT+Y3ERYTx_aw@mail.gmail.com> (raw)
In-Reply-To: <6bf87a65-1730-8a21-ac5a-d7d05219e024@crans.org>

On Wed, Jun 21, 2023 at 12:29 PM Johan Grande <nahoj@crans.org> wrote:
>
> When completion with _files or _path_files is called at the beginning of
> an argument, exclusion patterns given with `-F` are applied to
> already-escaped file names. This breaks patterns that contain escapable
> characters such as a space or [].
>
> With a \ added to the pattern, 'a a' is filtered out.

Upon closer examination, the documentation of the -F option is
imprecise.  -F is a substitute for the "ignored-patterns" zstyle, and
the description of that style clearly states that it filters out trial
completions.  Thus the -F option does not ignore files, it ignores the
strings that are candidates to be inserted on the command line when
completing files.

> But this is very brittle as it depends on the implementation of the
> escaping instead of the file names themselves.

Unfortunately this is implemented in the internals of the "compadd"
builtin and other forms of completion rely on it.

> Do you think that this behavior could be fixed?

We could try this.  However, it's not backward-compatible for people
who are already quoting spaces etc. for _files -F patterns.

diff --git a/Completion/Unix/Type/_path_files b/Completion/Unix/Type/_path_files
index d46dcbe5a..c471ad08e 100644
--- a/Completion/Unix/Type/_path_files
+++ b/Completion/Unix/Type/_path_files
@@ -100,6 +100,12 @@ if (( $#ignore )); then
   fi
 fi

+# Adjust the patterns for the effects of "compquote" on file names.
+# What's needed here is the inverse of ${(b)...}, that is, quote only
+# characters that are NOT pattern characters but might need quoting.
+# Backslashes appearing in a file name remain a bugaboo here.
+ignore=( ${ignore//(#b)([\!\#\$\&[:space:];\"\'])/\\${match[1]}} )
+
 # If we were given no file selection option, we behave as if we were given
 # a `-f'.


  reply	other threads:[~2023-06-22  3:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-21 19:29 Johan Grande
2023-06-22  3:54 ` Bart Schaefer [this message]
2023-06-24 19:55   ` Johan Grande
2023-07-20  5:15     ` Bart Schaefer

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

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

  git send-email \
    --in-reply-to='CAH+w=7Z4Ud0RxmzAaF6YZusxTVbSVD_feQiw8DT+Y3ERYTx_aw@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=nahoj@crans.org \
    --cc=zsh-workers@zsh.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.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).