zsh-workers
 help / color / mirror / code / Atom feed
* Empty $''
       [not found] ` <160303153436.ZM31948@torch.brasslantern.com>
@ 2016-03-03 23:36   ` Bart Schaefer
  2016-03-04 10:35     ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2016-03-03 23:36 UTC (permalink / raw)
  To: zsh-workers

On Mar 3,  3:34pm, Bart Schaefer wrote:
}
} $'...' is not a quoted expression, it's a substitution (at least as far
} as zsh is concerned).
} 
} This does appear to be out of step with other shells.

Comments on the below?


diff --git a/Src/subst.c b/Src/subst.c
index bb1dd89..efb62b8 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -146,7 +146,7 @@ stringsubstquote(char *strstart, char **pstrdpos)
     } else if (strdpos[len])
 	strret = dyncat(strsub, strdpos + len);
     else
-	strret = strsub;
+	strret = dyncat(strsub, nulstring);
 
     *pstrdpos = strret + (strdpos - strstart) + strlen(strsub);
 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Empty $''
  2016-03-03 23:36   ` Empty $'' Bart Schaefer
@ 2016-03-04 10:35     ` Peter Stephenson
  2016-03-04 12:14       ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2016-03-04 10:35 UTC (permalink / raw)
  To: zsh-workers

On Thu, 03 Mar 2016 15:36:47 -0800
Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Mar 3,  3:34pm, Bart Schaefer wrote:
> }
> } $'...' is not a quoted expression, it's a substitution (at least as far
> } as zsh is concerned).
> } 
> } This does appear to be out of step with other shells.
> 
> Comments on the below?

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

?

pws


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Empty $''
  2016-03-04 10:35     ` Peter Stephenson
@ 2016-03-04 12:14       ` Peter Stephenson
  2016-03-05 16:35         ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2016-03-04 12:14 UTC (permalink / raw)
  To: zsh-workers

On Fri, 4 Mar 2016 10:35:02 +0000
Peter Stephenson <p.stephenson@samsung.com> 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Empty $''
  2016-03-04 12:14       ` Peter Stephenson
@ 2016-03-05 16:35         ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2016-03-05 16:35 UTC (permalink / raw)
  To: zsh-workers

On Mar 4, 12:14pm, Peter Stephenson wrote:
} Subject: Re: Empty $''
}
} -    else
} +    else if (*strsub)
}  	strret = strsub;
} +    else {
} +	/* This ensures a $'' doesn't get elided. */
} +	strret = dupstring(nulstring);
} +    }

This looks fine; I wasn't sure whether (*strsub) was ever nonzero in
this case but it should be harmless to append a Nulstring to another
string (happens with e.g. foo"" already I think) so I took a shortcut.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-03-05 16:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1533e4d3e82.cbf3800a134118.3897690426664036468@enosys.org>
     [not found] ` <160303153436.ZM31948@torch.brasslantern.com>
2016-03-03 23:36   ` Empty $'' Bart Schaefer
2016-03-04 10:35     ` Peter Stephenson
2016-03-04 12:14       ` Peter Stephenson
2016-03-05 16:35         ` Bart Schaefer

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