Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Bug: cd auto-completion of .. fails with parentheses in directory name



Daniel Shahaf wrote on Fri, Oct 28, 2016 at 15:10:37 +0000:
> Mikael Magnusson wrote on Fri, Oct 28, 2016 at 03:56:08 +0200:
> > On Thu, Sep 22, 2016 at 7:30 PM, Bart Schaefer
> > <schaefer@xxxxxxxxxxxxxxxx> wrote:
> > > On Sep 22,  2:42pm, Daniel Shahaf wrote:
> > > }
> > > } 1) Is the lifetime correct?  I'm not sure whether elemnts of 'l' should
> > > } be malloc()ed or heap allocated.
> > >
> > > I think you have this correct -- completion is designed to put nearly
> > > all of its data in a private zsh heap that is discarded all at once
> > > when control returns to the line editor.  Only specific bits that persist
> > > across calls go into directly-malloc'd memory.
> > >
> > > } 2) Should quoting be added in bin_compfiles() or at a later point during
> > > } cf_pats()?  Although the docstring of cfp_test_exact() says the elements
> > > } of 'l' are filenames, they are then passed to ztat() which ignores
> > > } backslashes, so it's not clear to me what quoting is expected where.
> > >
> > > I think you have this in the right place, too, but I would be glad to
> > > have someone else confirm.  Or we can just put it in and see if any
> > > other examples break.
> > 
> > This patch breaks completion of
> > % mkdir '[a]'; touch '[a]/foo'
> > % ls \[a\]/<tab> # gives no results
> > 
> > for me. Reverting it on current master fixes it.
> 
> The new quotestring() is called in the input «\[a\]», (5 bytes), so it
> becomes double-escaped.

The following fixes it without breaking the original case; however, the
comment is a Sven original so I'm a bit wary of contravening it.

There are comments throughout the function asking which variables are
shell-quoted, pattern-quoted, or unquoted filenames.  In particular
there's such a comment in relation to $donepath, a variable which
depends on preserve-prefix and affects $tmp1 in the first iteration.
(In Mikael's example its value is "".)

We should get the data flow and data types of _path_files and compfiles
clarified and documented.  Until then, all these fixes will be just
shots in the dark.

As to this patch, however, I don't trust it enough to commit it.  We
could revert the previous patch (workers/39412) to prevent a regression
from 5.2...  but given that that patch prevents «cd 'foo(+pwd)'; cd
../<TAB>» from running the 'pwd' command, I'm not so keen on reverting
it, either.

Suggestions, anyone?

Cheers,

Daniel


diff --git a/Completion/Unix/Type/_path_files b/Completion/Unix/Type/_path_files
index 0d36b54..32942d7 100644
--- a/Completion/Unix/Type/_path_files
+++ b/Completion/Unix/Type/_path_files
@@ -594,7 +594,7 @@ for prepath in "$prepaths[@]"; do
     # There are more components, so skip over the next components and make a
     # slash be added.
 
-    tmp1=( ${tmp1//(#b)([][()|*?^#~<>\\=])/\\${match[1]}} )
+    #tmp1=( ${tmp1//(#b)([][()|*?^#~<>\\=])/\\${match[1]}} )
     tmp2="${(M)tpre##${~skips}}"
     if [[ -n "$tmp2" ]]; then
       skipped="/$tmp2"



Messages sorted by: Reverse Date, Date, Thread, Author