zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] vared: Escape empty elements of arrays
@ 2020-05-19 23:54 Daniel Shahaf
  2020-05-21  7:05 ` Daniel Shahaf
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Shahaf @ 2020-05-19 23:54 UTC (permalink / raw)
  To: zsh-workers; +Cc: Markus Näher

---
Found this while replying to Markus.

The %prep block is copied verbatim from several other Test/X*.ztst
files.  (Some of them do the zmodload at the end, but some not.  I guess
that doesn't matter.)

Cheers,

Daniel

 Src/Zle/zle_main.c       |  5 ++++-
 Test/X05zlebuiltins.ztst | 22 ++++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)
 create mode 100644 Test/X05zlebuiltins.ztst

diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index 8c0534708..2f6a53a40 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -1721,7 +1721,8 @@ bin_vared(char *name, char **args, Options ops, UNUSED(int func))
 	    return 1;
 	}
 	if (v->isarr) {
-	    /* Array: check for separators and quote them. */
+	    /* Array: check for separators and empty elements and quote them. */
+	    /* ### TODO: should probably use quotestring() rather than reinvent it */
 	    char **arr = getarrvalue(v), **aptr, **tmparr, **tptr;
 	    tptr = tmparr = (char **)zhalloc(sizeof(char *)*(arrlen(arr)+1));
 	    for (aptr = arr; *aptr; aptr++) {
@@ -1763,6 +1764,8 @@ bin_vared(char *name, char **args, Options ops, UNUSED(int func))
 		    *nptr = '\0';
 		    /* Stick this into the array of words to join up */
 		    *tptr++ = newstr;
+		} else if (t == *aptr) {
+		    *tptr++ = "''";
 		} else
 		    *tptr++ = *aptr; /* No, keep original array element */
 	    }
diff --git a/Test/X05zlebuiltins.ztst b/Test/X05zlebuiltins.ztst
new file mode 100644
index 000000000..1bf7b18b0
--- /dev/null
+++ b/Test/X05zlebuiltins.ztst
@@ -0,0 +1,22 @@
+%prep
+
+  if [[ $OSTYPE = cygwin ]]; then
+    ZTST_unimplemented="the zsh/zpty module does not work on Cygwin"
+  elif ( zmodload zsh/zpty 2>/dev/null ); then
+    . $ZTST_srcdir/comptest
+    comptestinit -z $ZTST_testdir/../Src/zsh
+  else
+    ZTST_unimplemented="the zsh/zpty module is not available"
+  fi
+
+%test
+
+  zpty_run 'a=("foo foo" "" "bar")'
+  zletest $'vared a\n\C-xw'
+0:vared: basic quoting test
+>BUFFER: foo\ foo '' bar
+>CURSOR: 15
+
+%clean
+
+  zmodload -ui zsh/zpty

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

end of thread, other threads:[~2020-05-21 16:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-19 23:54 [PATCH] vared: Escape empty elements of arrays Daniel Shahaf
2020-05-21  7:05 ` Daniel Shahaf
2020-05-21 10:57   ` Oliver Kiddle
2020-05-21 16:32     ` Daniel Shahaf

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