Module Name:    src
Committed By:   msaitoh
Date:           Sun Jun  9 11:13:11 UTC 2013

Modified Files:
        src/bin/sh [netbsd-5]: expand.c expand.h

Log Message:
Pull up following revision(s) (requested by gdt in ticket #1851):
        bin/sh/expand.c: revision 1.88
        bin/sh/expand.h: revision 1.19
Fix the expansion of "$(foo-$bar}" so that IFS isn't applied when
expanding $bar.
Noted by Greg Troxel on tech-userlevel running some 'git' tests.
Should fix PR bin/47361


To generate a diff of this commit:
cvs rdiff -u -r1.79.2.1 -r1.79.2.2 src/bin/sh/expand.c
cvs rdiff -u -r1.17 -r1.17.18.1 src/bin/sh/expand.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/sh/expand.c
diff -u src/bin/sh/expand.c:1.79.2.1 src/bin/sh/expand.c:1.79.2.2
--- src/bin/sh/expand.c:1.79.2.1	Wed Nov  2 19:31:19 2011
+++ src/bin/sh/expand.c	Sun Jun  9 11:13:11 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: expand.c,v 1.79.2.1 2011/11/02 19:31:19 riz Exp $	*/
+/*	$NetBSD: expand.c,v 1.79.2.2 2013/06/09 11:13:11 msaitoh Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)expand.c	8.5 (Berkeley) 5/15/95";
 #else
-__RCSID("$NetBSD: expand.c,v 1.79.2.1 2011/11/02 19:31:19 riz Exp $");
+__RCSID("$NetBSD: expand.c,v 1.79.2.2 2013/06/09 11:13:11 msaitoh Exp $");
 #endif
 #endif /* not lint */
 
@@ -246,7 +246,7 @@ argstr(char *p, int flag)
 			break;
 		default:
 			STPUTC(c, expdest);
-			if (flag & EXP_IFS_SPLIT & ifs_split && strchr(ifs, c) != NULL) {
+			if (flag & ifs_split && strchr(ifs, c) != NULL) {
 				/* We need to get the output split here... */
 				recordregion(expdest - stackblock() - 1,
 						expdest - stackblock(), 0);
@@ -690,8 +690,21 @@ again: /* jump here after setting a vari
 	}
 
 
-	apply_ifs = ((varflags & VSQUOTE) == 0 ||
-		(*var == '@' && shellparam.nparam != 1));
+	if (flag & EXP_IN_QUOTES)
+		apply_ifs = 0;
+	else if (varflags & VSQUOTE) {
+		if  (*var == '@' && shellparam.nparam != 1)
+		    apply_ifs = 1;
+		else {
+		    /*
+		     * Mark so that we don't apply IFS if we recurse through
+		     * here expanding $bar from "${foo-$bar}".
+		     */
+		    flag |= EXP_IN_QUOTES;
+		    apply_ifs = 0;
+		}
+	} else
+		apply_ifs = 1;
 
 	switch (subtype) {
 	case VSLENGTH:

Index: src/bin/sh/expand.h
diff -u src/bin/sh/expand.h:1.17 src/bin/sh/expand.h:1.17.18.1
--- src/bin/sh/expand.h:1.17	Sun Mar 25 06:29:27 2007
+++ src/bin/sh/expand.h	Sun Jun  9 11:13:11 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: expand.h,v 1.17 2007/03/25 06:29:27 apb Exp $	*/
+/*	$NetBSD: expand.h,v 1.17.18.1 2013/06/09 11:13:11 msaitoh Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -56,6 +56,7 @@ struct arglist {
 #define	EXP_REDIR	0x8	/* file glob for a redirection (1 match only) */
 #define EXP_CASE	0x10	/* keeps quotes around for CASE pattern */
 #define EXP_IFS_SPLIT	0x20	/* need to record arguments for ifs breakup */
+#define EXP_IN_QUOTES	0x40	/* don't set EXP_IFS_SPLIT again */
 
 
 union node;

Reply via email to