Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Buggy zed function



Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
> dixsept% which fctest
> fctest () {
>         cat <<< 'foo
> bar'
> }
> dixsept% fctest
> foo
> bar
> dixsept% autoload zed
> dixsept% zed -f fctest
> fctest () {
>         cat <<< 'foo
> bar'
> }
> dixsept% which fctest
> fctest () {
>         cat <<< "'foo
> bar'"
> }

It's not zed, you can see it just by entering

fctest () {
        cat <<< 'foo
bar'
}
which fctest

The argument from a here string is output in a slightly strange way.  The
only reason I can see is for just the case you have, when it's been input
as a here document.  In that case it's a raw string and needs quoting.  I
think that's OK; it's the other case that needs changing.  As far as I
know, we never get there directly from a here document since that shouldn't
produce tokens, so it should be good enough just to output that as a normal
string without the extra layer of quoting.  However, there may be a case
I've missed...

Index: Src/text.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/text.c,v
retrieving revision 1.15
diff -u -r1.15 text.c
--- Src/text.c	12 Apr 2005 15:11:12 -0000	1.15
+++ Src/text.c	10 Jan 2006 16:38:16 -0000
@@ -798,16 +798,17 @@
 	    taddstr(fstr[f->type]);
 	    if (f->type != REDIR_MERGEIN && f->type != REDIR_MERGEOUT)
 		taddchr(' ');
-	    if (f->type == REDIR_HERESTR) {
-                if (has_token(f->name)) {
-                    taddchr('\"');
-                    taddstr(bslashquote(f->name, NULL, 2));
-                    taddchr('\"');
-                } else {
-                    taddchr('\'');
-                    taddstr(bslashquote(f->name, NULL, 1));
-                    taddchr('\'');
-                }
+	    if (f->type == REDIR_HERESTR && !has_token(f->name)) {
+		/*
+		 * Strings that came from here-documents are converted
+		 * to here strings without quotation, so add that
+		 * now.  If tokens are already present taddstr()
+		 * will do the right thing (anyway, adding more
+		 * quotes certainly isn't right in that case).
+		 */
+		taddchr('\'');
+		taddstr(bslashquote(f->name, NULL, 1));
+		taddchr('\'');
 	    } else
 		taddstr(f->name);
 	    taddchr(' ');


-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


Your mail client is unable to display the latest news from CSR. To access our news copy this link into a web browser:  http://www.csr.com/email_sig.html



Messages sorted by: Reverse Date, Date, Thread, Author