Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/sh Fix the expansion of "$(foo-$bar}" so that IFS isn't ...



details:   https://anonhg.NetBSD.org/src/rev/dd9325de70cd
branches:  trunk
changeset: 783455:dd9325de70cd
user:      dsl <dsl%NetBSD.org@localhost>
date:      Sat Dec 22 20:15:22 2012 +0000

description:
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

diffstat:

 bin/sh/expand.c |  23 ++++++++++++++++++-----
 bin/sh/expand.h |   3 ++-
 2 files changed, 20 insertions(+), 6 deletions(-)

diffs (68 lines):

diff -r 01fa3812e00b -r dd9325de70cd bin/sh/expand.c
--- a/bin/sh/expand.c   Sat Dec 22 20:08:08 2012 +0000
+++ b/bin/sh/expand.c   Sat Dec 22 20:15:22 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: expand.c,v 1.87 2012/03/28 20:11:25 christos Exp $     */
+/*     $NetBSD: expand.c,v 1.88 2012/12/22 20:15:22 dsl 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.87 2012/03/28 20:11:25 christos Exp $");
+__RCSID("$NetBSD: expand.c,v 1.88 2012/12/22 20:15:22 dsl Exp $");
 #endif
 #endif /* not lint */
 
@@ -248,7 +248,7 @@
                        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);
@@ -703,8 +703,21 @@
        }
 
 
-       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:
diff -r 01fa3812e00b -r dd9325de70cd bin/sh/expand.h
--- a/bin/sh/expand.h   Sat Dec 22 20:08:08 2012 +0000
+++ b/bin/sh/expand.h   Sat Dec 22 20:15:22 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: expand.h,v 1.18 2011/06/18 21:18:46 christos Exp $     */
+/*     $NetBSD: expand.h,v 1.19 2012/12/22 20:15:22 dsl Exp $  */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -56,6 +56,7 @@
 #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;



Home | Main Index | Thread Index | Old Index