From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25011 invoked by alias); 22 Sep 2016 14:44:03 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 39412 Received: (qmail 9002 invoked from network); 22 Sep 2016 14:44:03 -0000 X-Qmail-Scanner-Diagnostics: from out2-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(66.111.4.26):SA:0(0.0/5.0):. Processed in 0.403373 secs); 22 Sep 2016 14:44:03 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at daniel.shahaf.name does not designate permitted sender hosts) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=vVF848qhJVbLgL7q yrenyjXCnjQ=; b=IdoaWww1ZdDLGZbGMP9CAWsnx+0hEC3iv0ErEukDlD7KD9gy 3urI2zK/9fNawOcpNTQj2CdwO9AXA34wbDrs1R7lp8kHNu2Cwip4sE3q8GD9ZuDN c22ng8BZUDtR6+Ese5R65SD0y3kmGBSO3GR2w+66Xd7dO7hX+371hW8/LzY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=vVF848qhJVbLgL7 qyrenyjXCnjQ=; b=CCrg/CX/3UzttW8rwgcl08xORE5ze3DsLv8HkvRuvc6X0eH oWurij9kJDr69q2raUOGWzF4h//BgyNpZor4KZGfl0iax+yeZW9ENLcSe1vwHzN1 v9uw7i93nFMegQNdSrhewPSzM0ekv+6AAj143KdHCxBXYCu46zgxCbyk65hg= X-Sasl-enc: 6SMno4y1CsCCMcwAlYl5QUrPe+J6dDSWy+KGtZzcVfn4 1474555438 Date: Thu, 22 Sep 2016 14:42:50 +0000 From: Daniel Shahaf To: Georg Nebehay Cc: zsh-workers@zsh.org Subject: Re: Bug: cd auto-completion of .. fails with parentheses in directory name Message-ID: <20160922144250.GA11076@fujitsu.shahaf.local2> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Georg Nebehay wrote on Wed, Sep 21, 2016 at 08:12:06 +0200: > there appears to be a bug in cd autocompletion. Please find the details > here: https://github.com/robbyrussell/oh-my-zsh/issues/5424 (For future reference, please restate the issue in the email, don't just link to an external description. Among other reasons: because github may shut down some day.) I can reproduce this with latest master: . % cd $(mktemp -d) % mkdir -p 'A(B)/C' % cd $_ % cd ../ . completes nothing. This is due to the following bit in _path_files: 463 elif [[ "$sopt" = *[/f]* ]]; then 464 compfiles -p$cfopt tmp1 accex "$skipped" "$_matcher $matcher[2]" "$sdirs" fake "$pats[@]" 465 else 466 compfiles -p$cfopt tmp1 accex "$skipped" "$_matcher $matcher[2]" '' fake "$pats[@]" 467 fi 468 tmp1=( $~tmp1 ) 2> /dev/null At entry to this code, tmp1=( $PWD ). compfiles changes that to tmp1=( '/tmp/tmp.elGZzgGNwi/A(B)/*(-/)' ), and line 468 the parentheses are interpreted as grouping characters. Now, bin_compfiles() calls cf_pats() calls cfp_test_exact(), which has a docstring, which says the values originating from $tmp1 are filenames. Not patterns. This means it is up to bin_compfiles() or its callees to quote the literal parentheses in the input. So perhaps this? — [[[ diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index 16b681c..27b78cd 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -4830,8 +4830,11 @@ cf_remove_other(char **names, char *pre, int *amb) * 3. compfiles -P parnam1 parnam2 skipped matcher sdirs parnam3 * * 1. Set parnam1 to an array of patterns.... + * ${(P)parnam1} is an in/out parameter. * 2. Like #1 but without calling cfp_opt_pats(). (This is only used by _approximate.) * 3. Like #1 but varargs is implicitly set to char *varargs[2] = { "*(-/)", NULL };. + * + * parnam2 has to do with the accept-exact style (see cfp_test_exact()). */ static int @@ -4866,7 +4869,7 @@ bin_compfiles(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) return 0; } for (l = newlinklist(); *tmp; tmp++) - addlinknode(l, *tmp); + addlinknode(l, quotestring(*tmp, QT_BACKSLASH_PATTERN)); set_list_array(args[1], cf_pats((args[0][1] == 'P'), !!args[0][2], l, getaparam(args[2]), args[3], args[4], args[5], ]]] Questions: 1) Is the lifetime correct? I'm not sure whether elemnts of 'l' should be malloc()ed or heap allocated. 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 haven't checked whether the rest of cf_pats() expects the elements of 'l' to be quoted or not.) Thanks for the bug report. Cheers, Daniel > Regards, > Georg