From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 304 invoked by alias); 27 Dec 2013 01:08:29 -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: 32186 Received: (qmail 14856 invoked from network); 27 Dec 2013 01:08:22 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 From: Bart Schaefer Message-id: <131226170827.ZM31040@torch.brasslantern.com> Date: Thu, 26 Dec 2013 17:08:27 -0800 X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Anybody know what's going on here in _expand? Patch? MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Line numbers for reference: 103 # Now try globbing. 104 105 [[ "$force" = *g* ]] || zstyle -T ":completion:${curcontext}:" glob && 106 eval 'exp=( ${~exp//(#b)\\[ 107 ]/$match[1]} ); exp=( ${(q)exp} )' 2>/dev/null There is a trailing space and tab on line 106. That stuff starting with //(#b) appears to want to replace any whitespace that is preceded by a backslash with *something*, but as there are no parens for the $match array to refer to, it ends up simply removing the whitespace (along with the backslash), at least as far as I can tell. That can't be correct ...? A bit further up is this: 89 eval 'exp=( ${${(e)exp//\\[ 90 ]/ }//(#b)([ 91 ])/\\$match[1]} )' 2>/dev/null That looks pretty similar (trailing space+tab on both lines 89 and 90) except there it's turning backslash-whitespace into just a space, and then adding back the backslash to any space that appears after applying the (e) flag. As it turns out, that eval on line 106 is where Yuri D'Elia's examples [from the "Expanding quotes" thread over on zsh-users] go wrong. Adding quote marks as well as whitespace to the character class on 106 "fixes" both examples. If nobody can explain what's correct about lines 106 and 107 as is, then I propose the following patch, which adds the seemingly missing backreference parens as well as putting quote chars in the class. diff --git a/Completion/Base/Completer/_expand b/Completion/Base/Completer/_expand index 44954a2..e52144c 100644 --- a/Completion/Base/Completer/_expand +++ b/Completion/Base/Completer/_expand @@ -103,8 +103,8 @@ subd=("$exp[@]") # Now try globbing. [[ "$force" = *g* ]] || zstyle -T ":completion:${curcontext}:" glob && - eval 'exp=( ${~exp//(#b)\\[ -]/$match[1]} ); exp=( ${(q)exp} )' 2>/dev/null + eval 'exp=( ${~exp//(#b)\\([ \"'"\'"' +])/$match[1]} ); exp=( ${(q)exp} )' 2>/dev/null ### Don't remember why we once used this instead of the (q) above. # eval 'exp=( ${~exp} ); exp=( ${exp//(#b)([][()|*?^#~<>\\=])/\\${match[1]}} )' 2>/dev/null