Subject: Re: Empty $''
From: Peter Stephenson <[email-masked]>
To: [email-masked]
Date: Fri, 04 Mar 2016 12:14:35 +0000
List-Id: Zsh Workers List <zsh-workers.zsh.org>

On Fri, 4 Mar 2016 10:35:02 +0000
Peter Stephenson <[email-masked]> wrote:
> nulstring always confused me, but something like this appears to be
> correct, so as long as this passes tests (we should presumably add
> another).
> 
> Hmm... actually, isn't the usual logic for using nulstring more like
> 
>     if (!*strsub)
>       strret = dupstring(nulstring);

Was thinking of something like...

diff --git a/Src/subst.c b/Src/subst.c
index bb1dd89..f2d0f65 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -145,8 +145,12 @@ stringsubstquote(char *strstart, char **pstrdpos)
 	    strret = dyncat(strstart, strsub);
     } else if (strdpos[len])
 	strret = dyncat(strsub, strdpos + len);
-    else
+    else if (*strsub)
 	strret = strsub;
+    else {
+	/* This ensures a $'' doesn't get elided. */
+	strret = dupstring(nulstring);
+    }
 
     *pstrdpos = strret + (strdpos - strstart) + strlen(strsub);
 
diff --git a/Test/A03quoting.ztst b/Test/A03quoting.ztst
index 0cf0e8a..da3ce35 100644
--- a/Test/A03quoting.ztst
+++ b/Test/A03quoting.ztst
@@ -74,3 +74,7 @@
 >16#61
 >16#62
 >16#64
+
+ () { print $# } '' "" $''
+0:$'' should not be elided, in common with other empty quotes
+>3