about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2003-05-07 09:41:56 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2003-05-07 09:41:56 +0000
commit6e77f38b925e3f37dc69b26efd6173df7281bbe8 (patch)
treec00a16dd163a04b8f996c3067cb458095751adcf
parent5d9ad06f9ffae341289356d1daa39e8628aa3f6d (diff)
downloadzsh-6e77f38b925e3f37dc69b26efd6173df7281bbe8.tar.gz
zsh-6e77f38b925e3f37dc69b26efd6173df7281bbe8.tar.xz
zsh-6e77f38b925e3f37dc69b26efd6173df7281bbe8.zip
18508: quoting of separator in ${foo//../..} was buggy
-rw-r--r--ChangeLog6
-rw-r--r--Src/subst.c19
-rw-r--r--Test/D04parameter.ztst12
3 files changed, 30 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 5d8fa1c14..dcf1c7b5f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2003-05-07  Peter Stephenson  <pws@csr.com>
+
+	* 18508: Src/subst.c, Test/D04parameter.ztst: quoting of the `/'
+	separating source and replacment text in ${foo//bar/stuff} was
+	buggy.
+
 2003-04-23  Peter Stephenson  <pws@pwstephenson.fsnet.co.uk>
 
 	* 18467: Src/Zle/computil.c: null pointer dereferenced with
diff --git a/Src/subst.c b/Src/subst.c
index 3533c1417..256e6d032 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -1366,15 +1366,20 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub)
 	     * If there isn't one, we're just going to delete that,
 	     * i.e. replace it with an empty string.
 	     *
-	     * This allows quotation of the slash with '\\/'. Why
-	     * two?  Well, for a non-quoted string we can check for
-	     * Bnull+/, which is what you get from `\/', but inside
-	     * double quotes the Bnull isn't there, so it's not
-	     * consistent.
+	     * We used to use double backslashes to quote slashes,
+	     * but actually that was buggy and using a single backslash
+	     * is easier and more obvious.
 	     */
 	    for (ptr = s; (c = *ptr) && c != '/'; ptr++)
-		if (c == '\\' && ptr[1] == '/')
-		    chuck(ptr);
+	    {
+		if ((c == Bnull || c == '\\') && ptr[1])
+		{
+		    if (ptr[1] == '/')
+			chuck(ptr);
+		    else
+			ptr++;
+		}
+	    }
 	    replstr = (*ptr && ptr[1]) ? ptr+1 : "";
 	    *ptr = '\0';
 	}
diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst
index 7e70691f7..1edd168cc 100644
--- a/Test/D04parameter.ztst
+++ b/Test/D04parameter.ztst
@@ -146,6 +146,18 @@
 0:array ${...:/...}
 >expletive deleted boldly claws dogs expletive deleted fight
 
+  str1='a\string\with\backslashes'
+  str2='a/string/with/slashes'
+  print "${str1//\\/-}"
+  print ${str1//\\/-}
+  print "${str2//\//-}"
+  print ${str2//\//-}
+0:use of backslashes in //-substitutions
+>a-string-with-backslashes
+>a-string-with-backslashes
+>a-string-with-slashes
+>a-string-with-slashes
+
   str1='twocubed'
   array=(the number of protons in an oxygen nucleus)
   print $#str1 ${#str1} "$#str1 ${#str1}" $#array ${#array} "$#array ${#array}"