summary refs log tree commit diff
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2007-09-24 16:17:20 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2007-09-24 16:17:20 +0800
commit880d95239e64f1dfd2b4fb49f32e1e0e59c69a67 (patch)
tree42e594dad1d31a24d4ed795008501f3f38f44637
parent[BUILTIN] test: little size and speed optimizations (diff)
downloaddash-880d95239e64f1dfd2b4fb49f32e1e0e59c69a67.tar.gz
dash-880d95239e64f1dfd2b4fb49f32e1e0e59c69a67.zip
[EXPAND] Do not quote back slashes in parameter expansions outside quotes
Test case:

	a=/b/c/*
	b=\\
	echo ${a%$b*}

Old result:

	/b/c/*

New result:

	/b/c/
-rw-r--r--ChangeLog4
-rw-r--r--src/expand.c5
-rw-r--r--src/mksyntax.c5
-rw-r--r--src/parser.c4
4 files changed, 12 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index b22197f..dca08d5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2007-09-24  Herbert Xu <herbert@gondor.apana.org.au>
+
+	* Do not quote back slashes in parameter expansions outside quotes.
+
 2007-09-22  Oleg Verych <olecom@flower.upol.cz>
 
 	* White space fixes for test(1).
diff --git a/src/expand.c b/src/expand.c
index db67c7c..3956112 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -895,7 +895,7 @@ memtodest(const char *p, size_t len, const char *syntax, int quotes) {
 		int c = (signed char)*p++;
 		if (c) {
 			if ((quotes & QUOTES_ESC) &&
-			    (syntax[c] == CCTL || syntax[c] == CBACK))
+			    (syntax[c] == CCTL || syntax[c] == CDBACK))
 				USTPUTC(CTLESC, q);
 		} else if (!(quotes & QUOTES_KEEPNUL))
 			continue;
@@ -1671,9 +1671,8 @@ _rmescapes(char *str, int flag)
 		}
 		if (*p == (char)CTLESC) {
 			p++;
-			if (notescaped && inquotes && *p != '/') {
+			if (notescaped && inquotes)
 				*q++ = '\\';
-			}
 		}
 		notescaped = globbing;
 copy:
diff --git a/src/mksyntax.c b/src/mksyntax.c
index 7a8a9ae..9ecbb45 100644
--- a/src/mksyntax.c
+++ b/src/mksyntax.c
@@ -53,6 +53,7 @@ struct synclass synclass[] = {
 	{ "CWORD",	"character is nothing special" },
 	{ "CNL",	"newline character" },
 	{ "CBACK",	"a backslash character" },
+	{ "CDBACK",	"a backslash character in double quotes" },
 	{ "CSQUOTE",	"single quote" },
 	{ "CDQUOTE",	"double quote" },
 	{ "CENDQUOTE",	"a terminating quote" },
@@ -175,7 +176,7 @@ main(int argc, char **argv)
 	init();
 	fputs("\n/* syntax table used when in double quotes */\n", cfile);
 	add("\n", "CNL");
-	add("\\", "CBACK");
+	add("\\", "CDBACK");
 	add("\"", "CENDQUOTE");
 	add("`", "CBQUOTE");
 	add("$", "CVAR");
@@ -193,7 +194,7 @@ main(int argc, char **argv)
 	init();
 	fputs("\n/* syntax table used when in arithmetic */\n", cfile);
 	add("\n", "CNL");
-	add("\\", "CBACK");
+	add("\\", "CDBACK");
 	add("`", "CBQUOTE");
 	add("$", "CVAR");
 	add("}", "CENDVAR");
diff --git a/src/parser.c b/src/parser.c
index 6faff17..279d49e 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -891,7 +891,9 @@ readtoken1(int firstc, char const *syntax, char *eofmark, int striptabs)
 					USTPUTC(CTLESC, out);
 				USTPUTC(c, out);
 				break;
-			case CBACK:	/* backslash */
+			/* backslash */
+			case CBACK:
+			case CDBACK:
 				c = pgetc2();
 				if (c == PEOF) {
 					USTPUTC(CTLESC, out);