From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14036 invoked by alias); 27 Dec 2013 18:05:57 -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: 32188 Received: (qmail 22212 invoked from network); 27 Dec 2013 18:05:41 -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: <131227100556.ZM25175@torch.brasslantern.com> Date: Fri, 27 Dec 2013 10:05:56 -0800 X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: While on the subject of expansion ... MIME-version: 1.0 Content-type: text/plain; charset=us-ascii I noticed that the built-in expand-word widget also mishandles the case with a backslashed quote. There's a bit of a disagreement between doexpansion() and get_comp_string() over who is responsible for what. get_comp_string() strips out the backslashes, but it also "leaves ... quotes unchanged when they are inside parameter expansions" according to the comment in doexpansion(). 2187 /* get_comp_string() leaves these quotes unchanged when they are 2188 * inside parameter expansions. */ 2189 for (ts = ss; *ts; ts++) 2190 if (*ts == '"') 2191 *ts = Dnull; 2192 else if (*ts == '\'') 2193 *ts = Snull; Therefore doexpansion() attempts to fix up the quotes, but gets it wrong in some of the cases because it doesn't have full context at each character position. The "inwhat" and "instring" globals give some hints but only for the position of the cursor, and there may be multiple differently-quoted substrings of the current word. Unlike the _expand completer which tries globbing separately from other expansions, doexpansion() attempts to set up for everything to expand at once [via a call to prefork()]. This makes the completion-oriented [de-]quoting applied by get_comp_string() problematic. I wonder which kinds of parameter expansions would break if we skipped that part. Again I suppose the theory is that quotes are much less likely to appear in globs than they are in parameter references, so handling the more common case is the right thing. Incidental aside: Both doexpansion() and expandorcomplete() contain code to fall back on docompletion() if expansion does not change the word, but I can't figure out how to get that branch in doexpansion() to ever be taken. It has something to do with words that start with a tilde.