summary refs log tree commit diff
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2007-09-25 10:54:13 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2007-09-25 10:54:13 +0800
commit170f44d00498bdb0e916e7efdc19a8d3489a381c (patch)
tree04da3c8817e14c0ee2f87a30ee6ab12b0234e032
parent[PARSER] Remove arithmetic expansion collapsing at parse time (diff)
downloaddash-170f44d00498bdb0e916e7efdc19a8d3489a381c.tar.gz
dash-170f44d00498bdb0e916e7efdc19a8d3489a381c.zip
[EXPAND] Do not expand tilde in parameter expansion within quotes
Previously code was added so that tilde expansion was carried out
parameter expansions within double quotes.  This change was made
with reference the behaviour of bash at the time.  Bash has since
be fixed so that this behaviour no longer occurs which is in line
with most other POSIX shells.

So this patch removes that behaviour in dash as well.

Test case:

	unset a
	echo "${a:-~root}"

Old result:

	/root

New result:

	~root
-rw-r--r--ChangeLog4
-rw-r--r--src/expand.c10
-rw-r--r--src/expand.h2
3 files changed, 8 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 7992485..dacc9b3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2007-09-25  Herbert Xu <herbert@gondor.apana.org.au>
+
+	* Do not expand tilde in parameter expansion within quotes.
+
 2007-09-24  Herbert Xu <herbert@gondor.apana.org.au>
 
 	* Do not quote back slashes in parameter expansions outside quotes.
diff --git a/src/expand.c b/src/expand.c
index 1443c14..c9f09ff 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -278,7 +278,7 @@ argstr(char *p, int flag)
 	const char *reject = spclchars;
 	int c;
 	int quotes = flag & QUOTES_ESC;
-	int breakall = flag & EXP_WORD;
+	int breakall = (flag & (EXP_WORD | EXP_QUOTED)) == EXP_WORD;
 	int inquotes;
 	size_t length;
 	int startloc;
@@ -296,8 +296,6 @@ argstr(char *p, int flag)
 		flag &= ~EXP_TILDE;
 tilde:
 		q = p;
-		if (*q == (char)CTLESC && (flag & EXP_QWORD))
-			q++;
 		if (*q == '~')
 			p = exptilde(p, q, flag);
 	}
@@ -780,10 +778,8 @@ again:
 	if (subtype == VSMINUS) {
 vsplus:
 		if (varlen < 0) {
-			argstr(
-				p, flag | EXP_TILDE |
-					(quoted ?  EXP_QWORD : EXP_WORD)
-			);
+			argstr(p, flag | EXP_TILDE | EXP_WORD |
+				  (quoted ? EXP_QUOTED : 0));
 			goto end;
 		}
 		if (easy)
diff --git a/src/expand.h b/src/expand.h
index 6b7d607..be7ec6f 100644
--- a/src/expand.h
+++ b/src/expand.h
@@ -56,7 +56,7 @@ struct arglist {
 #define EXP_RECORD	0x20	/* need to record arguments for ifs breakup */
 #define EXP_VARTILDE2	0x40	/* expand tildes after colons only */
 #define EXP_WORD	0x80	/* expand word in parameter expansion */
-#define EXP_QWORD	0x100	/* expand word in quoted parameter expansion */
+#define EXP_QUOTED	0x100	/* expand word in double quotes */
 
 
 union node;