svn commit: r222361 - in head: bin/sh
tools/regression/bin/sh/expansion
Jilles Tjoelker
jilles at FreeBSD.org
Fri May 27 15:56:14 UTC 2011
Author: jilles
Date: Fri May 27 15:56:13 2011
New Revision: 222361
URL: http://svn.freebsd.org/changeset/base/222361
Log:
sh: Fix unquoted $@/$* if IFS=''.
If IFS is null, unquoted $@/$* should still expand to separate words.
This differs from quoted $@ (which does not depend on IFS) in that pathname
generation is performed and empty words are removed.
Added:
head/tools/regression/bin/sh/expansion/ifs4.0 (contents, props changed)
Modified:
head/bin/sh/expand.c
Modified: head/bin/sh/expand.c
==============================================================================
--- head/bin/sh/expand.c Fri May 27 15:50:14 2011 (r222360)
+++ head/bin/sh/expand.c Fri May 27 15:56:13 2011 (r222361)
@@ -761,7 +761,8 @@ again: /* jump here after setting a vari
break;
record:
recordregion(startloc, expdest - stackblock(),
- varflags & VSQUOTE);
+ varflags & VSQUOTE || (ifsset() && ifsval()[0] == '\0' &&
+ (*var == '@' || *var == '*')));
break;
case VSPLUS:
@@ -947,7 +948,9 @@ numvar:
sep = ' ';
for (ap = shellparam.p ; (p = *ap++) != NULL ; ) {
strtodest(p, flag, subtype, quoted);
- if (*ap && sep)
+ if (!*ap)
+ break;
+ if (sep || (flag & EXP_FULL && !quoted && **ap != '\0'))
STPUTC(sep, expdest);
}
break;
Added: head/tools/regression/bin/sh/expansion/ifs4.0
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ head/tools/regression/bin/sh/expansion/ifs4.0 Fri May 27 15:56:13 2011 (r222361)
@@ -0,0 +1,39 @@
+# $FreeBSD$
+
+c=: e= s=' '
+failures=''
+ok=''
+
+check_result() {
+ if [ "x$2" = "x$3" ]; then
+ ok=x$ok
+ else
+ failures=x$failures
+ echo "For $1, expected $3 actual $2"
+ fi
+}
+
+IFS='
+'
+set -- a b '' c
+set -- $@
+check_result 'set -- $@' "($#)($1)($2)($3)($4)" "(3)(a)(b)(c)()"
+
+IFS=''
+set -- a b '' c
+set -- $@
+check_result 'set -- $@' "($#)($1)($2)($3)($4)" "(3)(a)(b)(c)()"
+
+set -- a b '' c
+set -- $*
+check_result 'set -- $*' "($#)($1)($2)($3)($4)" "(3)(a)(b)(c)()"
+
+set -- a b '' c
+set -- "$@"
+check_result 'set -- "$@"' "($#)($1)($2)($3)($4)" "(4)(a)(b)()(c)"
+
+set -- a b '' c
+set -- "$*"
+check_result 'set -- "$*"' "($#)($1)($2)($3)($4)" "(1)(abc)()()()"
+
+test "x$failures" = x
More information about the svn-src-all
mailing list