zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: bug with NO_UNSET option
@ 2010-10-19 10:57 Peter Stephenson
  0 siblings, 0 replies; only message in thread
From: Peter Stephenson @ 2010-10-19 10:57 UTC (permalink / raw)
  To: Zsh hackers list

A discussion on the Austin group mailing list suggests that when the
option NO_UNSET (-u) is in effect, not just ${foo} but ${foo#bar}
etc. should fail if foo is not set.  This was for standards compliance,
but it seems obviously right now it's pointed out so I think it's a
straightforward bug.

Index: Src/subst.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/subst.c,v
retrieving revision 1.107
diff -p -u -r1.107 subst.c
--- Src/subst.c	2 Oct 2010 19:55:30 -0000	1.107
+++ Src/subst.c	19 Oct 2010 10:52:56 -0000
@@ -2649,8 +2649,14 @@ paramsubst(LinkList l, LinkNode n, char 
 		}
 		getmatcharr(&aval, s, flags, flnum, replstr);
 	    } else {
-		if (vunset)
+		if (vunset) {
+		    if (unset(UNSET)) {
+			*idend = '\0';
+			zerr("%s: parameter not set", idbeg);
+			return NULL;
+		    }
 		    val = dupstring("");
+		}
 		if (!copied) {
 		    val = dupstring(val);
 		    copied = 1;
Index: Test/E01options.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/E01options.ztst,v
retrieving revision 1.22
diff -p -u -r1.22 E01options.ztst
--- Test/E01options.ztst	11 Aug 2008 08:40:57 -0000	1.22
+++ Test/E01options.ztst	19 Oct 2010 10:52:56 -0000
@@ -998,7 +998,7 @@
 >two
 >words
 
-  fn() { unset foo; print $foo; }
+  fn() { unset foo; print value is $foo; }
   setopt nounset
   print option unset unset by setting nounset
   eval fn
@@ -1008,9 +1008,32 @@
 0:UNSET option
 >option unset unset by setting nounset
 >option unset reset
->
+>value is
 ?fn: foo: parameter not set
 
+  fn1() { unset foo; print value 1 is ${foo#bar}; }
+  fn2() { unset foo; print value 2 is ${foo%bar}; }
+  fn3() { unset foo; print value 3 is ${foo/bar}; }
+  setopt nounset
+  print option unset unset by setting nounset
+  eval fn1
+  eval fn2
+  eval fn3
+  print option unset reset
+  setopt unset
+  fn1
+  fn2
+  fn3
+0:UNSET option with operators
+>option unset unset by setting nounset
+>option unset reset
+>value 1 is
+>value 2 is
+>value 3 is
+?fn1: foo: parameter not set
+?fn2: foo: parameter not set
+?fn3: foo: parameter not set
+
   fn() {
     emulate -L zsh
     setopt warncreateglobal

-- 
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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-10-19 10:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-19 10:57 PATCH: bug with NO_UNSET option Peter Stephenson

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).