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.
This commit is contained in:
parent
ca203c4faa
commit
715a0dd556
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=222361
@ -761,7 +761,8 @@ evalvar(char *p, int flag)
|
|||||||
break;
|
break;
|
||||||
record:
|
record:
|
||||||
recordregion(startloc, expdest - stackblock(),
|
recordregion(startloc, expdest - stackblock(),
|
||||||
varflags & VSQUOTE);
|
varflags & VSQUOTE || (ifsset() && ifsval()[0] == '\0' &&
|
||||||
|
(*var == '@' || *var == '*')));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VSPLUS:
|
case VSPLUS:
|
||||||
@ -947,7 +948,9 @@ varvalue(char *name, int quoted, int subtype, int flag)
|
|||||||
sep = ' ';
|
sep = ' ';
|
||||||
for (ap = shellparam.p ; (p = *ap++) != NULL ; ) {
|
for (ap = shellparam.p ; (p = *ap++) != NULL ; ) {
|
||||||
strtodest(p, flag, subtype, quoted);
|
strtodest(p, flag, subtype, quoted);
|
||||||
if (*ap && sep)
|
if (!*ap)
|
||||||
|
break;
|
||||||
|
if (sep || (flag & EXP_FULL && !quoted && **ap != '\0'))
|
||||||
STPUTC(sep, expdest);
|
STPUTC(sep, expdest);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
39
tools/regression/bin/sh/expansion/ifs4.0
Normal file
39
tools/regression/bin/sh/expansion/ifs4.0
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user