mirror of
git://git.code.sf.net/p/zsh/code
synced 2024-09-21 19:31:50 +02:00
40932: Parameter subscripts need to count parentheses.
Otherwise they can terminate in the middle of an expression.
This commit is contained in:
parent
207263a61e
commit
f6ab9a281d
@ -1,3 +1,8 @@
|
||||
2017-04-03 Peter Stephenson <p.stephenson@samsung.com>
|
||||
|
||||
* 40932: Src/params.c, Test/D06subscript.ztst: parameter
|
||||
subscripts need to count parentheses to avoid terminating early.
|
||||
|
||||
2017-04-02 Barton E. Schaefer <schaefer@zsh.org>
|
||||
|
||||
* 40929 (replaces 40598): Src/subst.c: paramsubst() should always
|
||||
|
11
Src/params.c
11
Src/params.c
@ -1183,7 +1183,7 @@ getarg(char **str, int *inv, Value v, int a2, zlong *w,
|
||||
int *prevcharlen, int *nextcharlen)
|
||||
{
|
||||
int hasbeg = 0, word = 0, rev = 0, ind = 0, down = 0, l, i, ishash;
|
||||
int keymatch = 0, needtok = 0, arglen, len;
|
||||
int keymatch = 0, needtok = 0, arglen, len, inpar = 0;
|
||||
char *s = *str, *sep = NULL, *t, sav, *d, **ta, **p, *tt, c;
|
||||
zlong num = 1, beg = 0, r = 0, quote_arg = 0;
|
||||
Patprog pprog = NULL;
|
||||
@ -1322,8 +1322,9 @@ getarg(char **str, int *inv, Value v, int a2, zlong *w,
|
||||
}
|
||||
|
||||
for (t = s, i = 0;
|
||||
(c = *t) && ((c != Outbrack &&
|
||||
(ishash || c != ',')) || i); t++) {
|
||||
(c = *t) &&
|
||||
((c != Outbrack && (ishash || c != ',')) || i || inpar);
|
||||
t++) {
|
||||
/* Untokenize inull() except before brackets and double-quotes */
|
||||
if (inull(c)) {
|
||||
c = t[1];
|
||||
@ -1344,6 +1345,10 @@ getarg(char **str, int *inv, Value v, int a2, zlong *w,
|
||||
i++;
|
||||
else if (c == ']' || c == Outbrack)
|
||||
i--;
|
||||
if (c == '(' || c == Inpar)
|
||||
inpar++;
|
||||
else if (c == ')' || c == Outpar)
|
||||
inpar--;
|
||||
if (ispecial(c))
|
||||
needtok = 1;
|
||||
}
|
||||
|
@ -266,3 +266,10 @@
|
||||
>of the gang
|
||||
>of the gang
|
||||
>of the gang
|
||||
|
||||
string='abcde'
|
||||
twoarg() { return $(( $2 - $1 )) }
|
||||
functions -M twoarg
|
||||
print ${string[1,twoarg(1,4)]}
|
||||
0:Commas inside parentheses do not confuse subscripts
|
||||
>abc
|
||||
|
Loading…
Reference in New Issue
Block a user