about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2000-08-29 20:27:47 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2000-08-29 20:27:47 +0000
commit942009eb9f6451915f23d921c0f49d3102dbd26c (patch)
tree545058d77263ab4e4a40f0665c1925786f777861
parentf4f38507e54ad19ea28395f977637bb3f014c9dc (diff)
downloadzsh-942009eb9f6451915f23d921c0f49d3102dbd26c.tar.gz
zsh-942009eb9f6451915f23d921c0f49d3102dbd26c.tar.xz
zsh-942009eb9f6451915f23d921c0f49d3102dbd26c.zip
12719: quoting arrays in vared with real backslashes
-rw-r--r--ChangeLog6
-rw-r--r--Doc/Zsh/mod_zle.yo9
-rw-r--r--Src/Zle/zle_main.c9
-rw-r--r--Src/utils.c9
4 files changed, 23 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 15fb5d7fa..e46908f0b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2000-08-29  Peter Stephenson  <pws@pwstephenson.fsnet.co.uk>
+
+	* 12719: Doc/Zsh/mod_zle.yo, Src/utils.c, Src/Zle/zle_main.c:
+	handle quoting of separators in arrays when there might also be
+	real backslashes around.
+
 2000-08-29  Sven Wischnowsky  <wischnow@zsh.org>
 
 	* 12717: Src/Zle/zle_tricky.c: fix for unbalanced calls to
diff --git a/Doc/Zsh/mod_zle.yo b/Doc/Zsh/mod_zle.yo
index f858b35d7..3b4d58ed7 100644
--- a/Doc/Zsh/mod_zle.yo
+++ b/Doc/Zsh/mod_zle.yo
@@ -162,10 +162,11 @@ If the type of an existing parameter does not match the type to be
 created, the parameter is unset and recreated.
 
 If an array or array slice is being edited, separator characters as defined
-in tt($IFS) will be shown quoted with a backslash.  Conversely, when the
-edited text is split into an array, a backslash quotes an immediately
-following separator character; no other special handling of backslashes, or
-any handling of quotes, is performed.
+in tt($IFS) will be shown quoted with a backslash, as will backslashes
+themselves.  Conversely, when the edited text is split into an array, a
+backslash quotes an immediately following separator character or backslash;
+no other special handling of backslashes, or any handling of quotes, is
+performed.
 
 Individual elements of existing array or associative array parameters
 may be edited by using subscript syntax on var(name).  New elements are
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index f02b2b75d..e02ea14b8 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -839,13 +839,16 @@ bin_vared(char *name, char **args, char *ops, int func)
 	    tptr = tmparr = (char **)zhalloc(sizeof(char *)*(arrlen(arr)+1));
 	    for (aptr = arr; *aptr; aptr++) {
 		int sepcount = 0;
-		/* See if this word contains a separator character */
+		/*
+		 * See if this word contains a separator character
+		 * or backslash
+		 */
 		for (t = *aptr; *t; t++) {
 		    if (*t == Meta) {
 			if (isep(t[1] ^ 32))
 			    sepcount++;
 			t++;
-		    } else if (isep(*t))
+		    } else if (isep(*t) || *t == '\\')
 			sepcount++;
 		}
 		if (sepcount) {
@@ -858,7 +861,7 @@ bin_vared(char *name, char **args, char *ops, int func)
 			    if (isep(t[1] ^ 32))
 				*nptr++ = '\\';
 			    *nptr++ = *t++;
-			} else if (isep(*t))
+			} else if (isep(*t) || *t == '\\')
 			    *nptr++ = '\\';
 			*nptr++ = *t++;
 		    }
diff --git a/Src/utils.c b/Src/utils.c
index 689680f1c..ab5fbbeb4 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -1829,6 +1829,8 @@ skipwsep(char **s)
     return i;
 }
 
+/* see findsep() below for handling of `quote' argument */
+
 /**/
 mod_export char **
 spacesplit(char *s, int allownull, int heap, int quote)
@@ -1854,7 +1856,7 @@ spacesplit(char *s, int allownull, int heap, int quote)
     else if (!allownull && t != s)
 	*ptr++ = dup("");
     while (*s) {
-	if (isep(*s == Meta ? s[1] ^ 32 : *s)) {
+	if (isep(*s == Meta ? s[1] ^ 32 : *s) || (quote && *s == '\\')) {
 	    if (*s == Meta)
 		s++;
 	    s++;
@@ -1891,7 +1893,8 @@ findsep(char **s, char *sep, int quote)
      * quote is a flag that '\<sep>' should not be treated as a separator.
      * in this case we need to be able to strip the backslash directly
      * in the string, so the calling function must have sent us something
-     * modifiable.  currently this only works for sep == NULL.
+     * modifiable.  currently this only works for sep == NULL.  also in
+     * in this case only, we need to turn \\ into \.
      */
     int i;
     char *t, *tt;
@@ -1899,7 +1902,7 @@ findsep(char **s, char *sep, int quote)
     if (!sep) {
 	for (t = *s; *t; t++) {
 	    if (quote && *t == '\\' &&
-		isep(t[1] == Meta ? (t[2] ^ 32) : t[1])) {
+		(isep(t[1] == Meta ? (t[2] ^ 32) : t[1]) || t[1] == '\\')) {
 		chuck(t);
 		if (*t == Meta)
 		    t++;