zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk, 255788-forwarded@bugs.debian.org
Subject: PATCH: (2): Bug#255788: $'' does not work after <<<
Date: Mon, 28 Jun 2004 12:39:54 +0100	[thread overview]
Message-ID: <200406281139.i5SBdtc5013590@news01.csr.com> (raw)
In-Reply-To: "Peter Stephenson"'s message of "Sun, 27 Jun 2004 20:44:09 BST." <20040627194410.C1E72865D@pwstephenson.fsnet.co.uk>

OK, it's Monday morning and I spent the entire weekend thinking about
book rewrites and tax returns, so...

Here's a second go, with additions to the test suite.  Since I'm now
very confused, here's an exhausting (sic) list of changes.

Here documents: Nothing changed in the body of the here document.  In
parsing the word after <<, handle all forms of quoting.  ' is unchanged;
" unchanged; ` now does the same thing as double quotes, which means \\
gets turned into \, etc.; backquotes don't do command substitution ---
they never did, but they wouldn't have been stripped properly.  $'...'
now has its standard effect.  (We should probably do that during the
lexical analysis phase, which corresponds to Bart's last point.
However, it seems to be working using the new function quotesubst(), so
I haven't looked at this.)

Here strings: They sort of did expansion before (and this was
documented), but it was a bit botched because the string was massaged to
remove quotes too early.  (The dupstring() has now gone along with the
remnulargs(), for those who care about such things.)  So the test in
A04redirect.ztst with a double-quoted $foo worked but $'...' didn't
work.  This should be more consistent, doing zsh's standard forced
single-word substitution (make sure arrays don't turn it into multiple
words, etc.).  I still don't see any reason why this would be the wrong
thing to do.

Index: Doc/Zsh/redirect.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/redirect.yo,v
retrieving revision 1.6
diff -u -r1.6 redirect.yo
--- Doc/Zsh/redirect.yo	2 May 2003 10:25:32 -0000	1.6
+++ Doc/Zsh/redirect.yo	28 Jun 2004 11:36:26 -0000
@@ -70,12 +70,20 @@
 and `tt(\)' must be used to quote the characters
 `tt(\)', `tt($)', `tt(`)' and the first character of var(word).
 
+Note that var(word) itself does not undergo shell expansion.
+Backquotes in var(word) do not have their usual effect, and
+behave similarly to double quotes.  Quotes in the
+form tt($')var(...)tt(') have their standard effect of expanding
+backslashed references to special characters.
+
 If tt(<<-) is used, then all leading
 tabs are stripped from var(word) and from the document.
 )
 item(tt(<<<) var(word))(
 Perform shell expansion on var(word) and pass the result
 to standard input.  This is known as a em(here-string).
+Compare the use of var(word) in here-documents above, where var(word)
+does not undergo shell expansion.
 )
 xitem(tt(<&) var(number))
 item(tt(>&) var(number))(
Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.65
diff -u -r1.65 exec.c
--- Src/exec.c	22 Jun 2004 13:10:02 -0000	1.65
+++ Src/exec.c	28 Jun 2004 11:36:27 -0000
@@ -2714,9 +2714,10 @@
 
     for (s = str; *s; s++)
 	if (INULL(*s)) {
-	    *s = Nularg;
 	    qt = 1;
+	    break;
 	}
+    quotesubst(str);
     untokenize(str);
     if (typ == REDIR_HEREDOCDASH) {
 	strip = 1;
Index: Src/parse.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/parse.c,v
retrieving revision 1.45
diff -u -r1.45 parse.c
--- Src/parse.c	22 Jun 2004 13:10:02 -0000	1.45
+++ Src/parse.c	28 Jun 2004 11:36:28 -0000
@@ -1754,9 +1754,6 @@
 	if ((tokstr[0] == Inang || tokstr[0] == Outang) && tokstr[1] == Inpar)
 	    type = tokstr[0] == Inang ? REDIR_INPIPE : REDIR_OUTPIPE;
 	break;
-    case REDIR_HERESTR:
-        remnulargs(name = dupstring(name));
-        break;
     }
     yylex();
 
Index: Src/subst.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/subst.c,v
retrieving revision 1.38
diff -u -r1.38 subst.c
--- Src/subst.c	2 Jun 2004 22:14:26 -0000	1.38
+++ Src/subst.c	28 Jun 2004 11:36:29 -0000
@@ -231,6 +231,37 @@
     return errflag ? NULL : node;
 }
 
+/*
+ * Simplified version of the prefork/singsub processing where
+ * we only do substitutions appropriate to quoting.  Currently
+ * this means only the expansions in $'....'.  This is used
+ * for the end tag for here documents.  As we are not doing
+ * `...` expansions, we just use those for quoting and removing
+ * them from the text (they do not get removed by remnulargs()).
+ *
+ * The remnulargs() makes this consistent with the other forms
+ * of substitution, indicating that quotes have been fully
+ * processed.
+ */
+
+/**/
+void
+quotesubst(char *str)
+{
+    char *s = str;
+
+    while (*s) {
+	if (*s == String && s[1] == Snull) {
+	    s = getkeystring(s, NULL, 4, NULL);
+	} else if (*s == Tick || *s == Qtick) {
+	    chuck(s);
+	} else {
+	    s++;
+	}
+    }
+    remnulargs(str);
+}
+
 /**/
 mod_export void
 globlist(LinkList list, int nountok)
Index: Test/A04redirect.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/A04redirect.ztst,v
retrieving revision 1.4
diff -u -r1.4 A04redirect.ztst
--- Test/A04redirect.ztst	2 May 2003 10:25:33 -0000	1.4
+++ Test/A04redirect.ztst	28 Jun 2004 11:36:29 -0000
@@ -50,10 +50,34 @@
 0:Here-documents stripping tabs
 >barbar
 
+  cat <<-$'$HERE '`$(THERE) `'$((AND)) '"\EVERYWHERE"
+# tabs again.  sorry about the max miller.
+	Here's a funny thing.  Here is a funny thing.
+	I went home last night.  There's a funny thing.
+	Man walks into a $foo.  Ouch, it's an iron $foo.
+	$HERE $(THERE) $((AND)) \EVERYWHERE
+0:Here-documents don't perform shell expansion on the initial word
+>Here's a funny thing.  Here is a funny thing.
+>I went home last night.  There's a funny thing.
+>Man walks into a $foo.  Ouch, it's an iron $foo.
+
+  cat <<-$'\x45\x4e\x44\t\x44\x4f\x43'
+# tabs again
+	This message is unfathomable.
+	END	DOC
+0:Here-documents do perform $'...' expansion on the initial word
+>This message is unfathomable.
+
   cat <<<"This is a line with a $foo in it"
 0:'<<<' redirection
 >This is a line with a bar in it
 
+  cat <<<$'a\nb\nc'
+0:here-strings with $'...' quoting
+>a
+>b
+>c
+
   exec 3>redir  &&  print hello >&3  &&  print goodbye >&3  && cat redir
 0:'>&' redirection
 >hello

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


  reply	other threads:[~2004-06-28 11:40 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20040623023305.GA15259@localhost>
2004-06-23 17:55 ` Clint Adams
2004-06-23 18:56   ` Bart Schaefer
2004-06-25  9:55   ` Peter Stephenson
2004-06-26 18:34     ` Bart Schaefer
2004-06-27  0:07       ` Peter Stephenson
2004-06-27 17:04         ` Bart Schaefer
2004-06-27 17:45           ` Peter Stephenson
2004-06-27 18:37             ` Bart Schaefer
2004-06-27 19:44               ` Peter Stephenson
2004-06-28 11:39                 ` Peter Stephenson [this message]
2004-06-28 15:14                   ` PATCH: (2): " Bart Schaefer
2004-06-28 15:29                     ` Peter Stephenson
2004-06-28 15:39                       ` Peter Stephenson
2004-06-28 17:26                       ` Bart Schaefer
2004-06-30 10:00                         ` Peter Stephenson
2004-06-30 15:58                           ` Bart Schaefer

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=200406281139.i5SBdtc5013590@news01.csr.com \
    --to=pws@csr.com \
    --cc=255788-forwarded@bugs.debian.org \
    --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).