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

[PATCH] vared: Escape empty elements of arrays



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



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