zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk
Subject: Re: completion bug: treats substitution of unset parameter as empty string
Date: Thu, 10 Sep 2009 15:40:53 +0100	[thread overview]
Message-ID: <20090910154053.3de0f8eb@news01> (raw)
In-Reply-To: <m3hbvana7h.fsf@klanderman.net>

On Thu, 10 Sep 2009 10:30:42 -0400
Greg Klanderman <gak@klanderman.net> wrote:
> Here's a patch to fix the originally reported problem - that
> _path_files incorrectly treats a parameter expansion of an
> unset parameter as the empty string, i.e. that
> 
> % ls $foobar/ <tab>
> 
> lists completions under '/'.

That's fine, however I think (belatedly answering your other question)
that, since we don't need to backport this anywhere, using an anonymous
function would be neater---so we're not relying on the value of "nounset"
outside.  In practice if it were set outside all hell would break loose, so
this is pretty pernickety, but perhaps it's a useful precedent.

Index: Completion/Unix/Type/_path_files
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_path_files,v
retrieving revision 1.47
diff -u -r1.47 _path_files
--- Completion/Unix/Type/_path_files	5 Aug 2009 00:46:45 -0000	1.47
+++ Completion/Unix/Type/_path_files	10 Sep 2009 14:36:56 -0000
@@ -247,7 +247,11 @@
   # meant as a partial path.
 
   linepath="${(M)pre##*\$[^/]##/}"
-  eval 'realpath=${(e)~linepath}' 2>/dev/null
+  function {
+    # do not treat an unset parameter expansion as the empty string
+    setopt localoptions nounset
+    eval 'realpath=${(e)~linepath}' 2>/dev/null
+  }
   [[ -z "$realpath" || "$realpath" = "$linepath" ]] && return 1
   pre="${pre#${linepath}}"
   i='[^/]'

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom


  reply	other threads:[~2009-09-10 14:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-29 18:25 Greg Klanderman
2009-09-09  4:10 ` Greg Klanderman
2009-09-10  9:26   ` Peter Stephenson
2009-09-10 14:30     ` Greg Klanderman
2009-09-10 14:40       ` Peter Stephenson [this message]
2009-09-10 15:23         ` Greg Klanderman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090910154053.3de0f8eb@news01 \
    --to=pws@csr.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).