zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: <<<: Document newline behavior and fix optimization
@ 2022-03-08 18:58 Mikael Magnusson
  2022-03-08 19:38 ` Bart Schaefer
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Mikael Magnusson @ 2022-03-08 18:58 UTC (permalink / raw)
  To: zsh-workers

The =(<<<foo) optimization forgot to add a newline, but =(cat<<<foo)
always did, make the behavior consistent, and document it.
---

This optimization was added in 2005 in workers/21758 (ad2bd42c858) and
has no motivation for excluding the newline, so I assume it's just a
minor mistake.
---
 Doc/Zsh/redirect.yo   | 3 ++-
 README                | 5 +++++
 Src/exec.c            | 4 +++-
 Test/A04redirect.ztst | 2 +-
 4 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/Doc/Zsh/redirect.yo b/Doc/Zsh/redirect.yo
index 2b48974b40..fd40ab5a4b 100644
--- a/Doc/Zsh/redirect.yo
+++ b/Doc/Zsh/redirect.yo
@@ -86,7 +86,8 @@ 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.
+does not undergo shell expansion.  The result will have a trailing newline
+after it.
 )
 xitem(tt(<&) var(number))
 item(tt(>&) var(number))(
diff --git a/README b/README
index 353667289e..153f02b25b 100644
--- a/README
+++ b/README
@@ -33,6 +33,11 @@ details, see the documentation.
 Incompatibilities since 5.8
 ---------------------------
 
+The optimization for the =(<<<foo) construct with no command, which
+creates a temporary file with contents "foo", now adds a newline byte
+after "foo" for consistency with the behaviour of the <<< redirection
+everywhere else.
+
 PROMPT_SUBST expansion is no longer performed on arguments to prompt-
 expansion sequences such as %F.
 
diff --git a/Src/exec.c b/Src/exec.c
index f67074846f..70cbfc97fd 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -4836,8 +4836,10 @@ getoutputfile(char *cmd, char **eptr)
 	singsub(&s);
 	if (errflag)
 	    s = NULL;
-	else
+	else {
 	    untokenize(s);
+	    s = dyncat(s, "\n");
+	}
     }
 
     if (!s)             /* Unclear why we need to do this before open() */
diff --git a/Test/A04redirect.ztst b/Test/A04redirect.ztst
index 993138e7dc..17f6dfa29a 100644
--- a/Test/A04redirect.ztst
+++ b/Test/A04redirect.ztst
@@ -440,7 +440,7 @@
 # This tests the here-string to filename optimisation; we can't
 # test that it's actually being optimised, but we can test that it
 # still works.
-  cat =(<<<$'This string has been replaced\nby a file containing it.\n')
+  cat =(<<<$'This string has been replaced\nby a file containing it.')
 0:Optimised here-string to filename
 >This string has been replaced
 >by a file containing it.
-- 
2.15.1



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

end of thread, other threads:[~2022-03-30  8:03 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-08 18:58 PATCH: <<<: Document newline behavior and fix optimization Mikael Magnusson
2022-03-08 19:38 ` Bart Schaefer
2022-03-08 19:42   ` Bart Schaefer
2022-03-09 11:10     ` Stephane Chazelas
2022-03-13 18:50 ` Stephane Chazelas
2022-03-13 19:28   ` Mikael Magnusson
2022-03-13 19:35     ` Stephane Chazelas
2022-03-30  7:17 ` Jun T
2022-03-30  8:02   ` Mikael Magnusson

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