From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: zsh-workers-return-43752-ml=inbox.vuxu.org@zsh.org X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id f0f121f4 for ; Fri, 2 Nov 2018 22:18:55 +0000 (UTC) Received: (qmail 11898 invoked by alias); 2 Nov 2018 22:18:43 -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: List-Unsubscribe: X-Seq: 43752 Received: (qmail 8779 invoked by uid 1010); 2 Nov 2018 22:18:43 -0000 X-Qmail-Scanner-Diagnostics: from know-smtprelay-omc-10.server.virginmedia.net 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(80.0.253.74):SA:0(-2.0/5.0):. Processed in 4.135377 secs); 02 Nov 2018 22:18:43 -0000 X-Envelope-From: p.w.stephenson@ntlworld.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | X-Originating-IP: [86.16.88.158] X-Authenticated-User: p.w.stephenson@ntlworld.com X-Spam: 0 X-Authority: v=2.3 cv=Ipswjo3g c=1 sm=1 tr=0 a=MiHCjVqLJ44lE3bxSlffFQ==:117 a=MiHCjVqLJ44lE3bxSlffFQ==:17 a=kj9zAlcOel0A:10 a=KrHTQlyhAAAA:8 a=cxs95D__TPyi5Ue0-WcA:9 a=CjuIK1q_8ugA:10 a=NeM01qLVy57-G_-UPP7B:22 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ntlworld.com; s=meg.feb2017; t=1541196419; bh=mzhXkYJF6eeKHs96/yy7Y4Lzh+zlQhCPfZp/buGaK80=; h=Date:From:To:Subject:In-Reply-To:References; b=z5pjbpHTqAtkLwks+JdpP4rebOhCqb2jf7mVM0Wr1gCSWiYTph8rkLFpPhvuDkGxf 3KuK9ZAYK/2TqWOXHGP5V0YfIxp7piNfEG0d4O9JP/Qt9CvfbW7bonccexzSbjQqSF s/+lpKhS2IqNZMD3DJlhKW8wbYBNq10fApkj0TE4TrgBSRElfslrWV1ss1G9bRzpUT a2/eJPUJFTDN0LzAt6ZJxsyaA8gPSka1ESIdQXJ8hYbBr2dg47B4/gZWbHAj6W59VL PvFFS2FhWqEo0+x5rxy7AStnP+jBR1cmlrrHboCNHEPwhKm0jy7luNRHDSA78a4sK0 TwRXhuSQwSQpg== Date: Fri, 2 Nov 2018 22:06:57 +0000 From: Peter Stephenson To: Zsh list Subject: Re: Non-escaped special chars from var expansion Message-ID: <20181102220657.396df24a@pws-HP.localdomain> In-Reply-To: References: X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4wfGpYANjV6dn4e6NFOIlWNisLLAzcvMX86RIIF1OKHsLag0gKC2d4a7wA9CtB1vQwDTqXI+sMdOAXk2P7YTdU5AKlVYvdNW7NoY4Kthjrfy/RsowHgqNu 8T/URR+4boPKd0/Bx4AvSG6d69BiS4+X1Y9QmOzgkr+uYu9RlVX5gH687woc1nquUBwNBy1KJ1FAtw== On Fri, 2 Nov 2018 13:39:26 -0700 Wayne Davison wrote: > I have a particular compinit setup where special-chars from a var (other > than spaces) are not backslash-escaped. To duplicate: > > zsh -f > autoload -Uz compinit > compinit > zstyle ':completion:*' completer _oldlist _expand _complete _match _ignored > _files _prefix > zstyle ':completion:*:expand:*' tag-order all-expansions > bindkey -e > bindkey '\t' complete-word > mkdir 'foo; bar (baz)' > cd !:1 > cd $PWD > > The result is "cd foo;\ bar\ (baz)" instead of "cd foo\;\ bar\ \(baz\)". Don't breathe too loudly but I *think* I might have worked out what's going on. (Which the author of the code obviously wasn't banking on.) Your file name is making the attempted glob fail; it's been deliberately silenced, so you don't notice. But that also has the effect of abandoning the attempt to quote the expression. So I think we need to apply the quoting without the "~" that turns on active glob characters any time we didn't get globbing to work. (Whether the globbing should actually have worked is a question I haven't gone into. But I suspect it's not a problem --- the _expand function is trying lots of things not all of which will work.) Maybe? diff --git a/Completion/Base/Completer/_expand b/Completion/Base/Completer/_expand index ee3681bad..f4909826a 100644 --- a/Completion/Base/Completer/_expand +++ b/Completion/Base/Completer/_expand @@ -103,9 +103,19 @@ subd=("$exp[@]") # Now try globbing. -[[ "$force" = *g* ]] || zstyle -T ":completion:${curcontext}:" glob && - eval 'exp=( ${~exp//(#b)\\([ \"'"\'"' +# We need to come out of this with consistent quoting, by hook or by crook. +integer done_quote +local orig_exp=$exp +if [[ "$force" = *g* ]] || zstyle -T ":completion:${curcontext}:" glob; then + eval 'exp=( ${~exp//(#b)\\([ \"'"\'"' +])/$match[1]} ); exp=( ${(q)exp} )' 2>/dev/null && done_quote=1 +fi +# If the globbing failed, or we didn't try globbing, we'll do +# it again without the "~" so globbing is simply omitted. +if (( ! done_quote )); then + eval 'exp=( ${orig_exp//(#b)\\([ \"'"\'"' ])/$match[1]} ); exp=( ${(q)exp} )' 2>/dev/null +fi ### Don't remember why we once used this instead of the (q) above. # eval 'exp=( ${~exp} ); exp=( ${exp//(#b)([][()|*?^#~<>\\=])/\\${match[1]}} )' 2>/dev/null