Fix subscripting bug with backslash-double-quote.

This commit is contained in:
Bart Schaefer 2001-04-23 15:30:22 +00:00
parent fe4a49488c
commit fc4511ecb7
4 changed files with 32 additions and 9 deletions

View file

@ -1,3 +1,9 @@
2001-04-23 Bart Schaefer <schaefer@zsh.org>
* 14070: Src/lex.c, Src/params.c, Test/D06subscript.ztst: Fix
problem with parsing \" in subscripts during parameter expansion
in double-quotes.
2001-04-22 Bart Schaefer <schaefer@zsh.org>
* 14066: Doc/Zsh/expn.yo, Doc/Zsh/params.yo, Src/params.c,

View file

@ -1305,7 +1305,8 @@ dquote_parse(char endchar, int sub)
c == endchar || c == '`' ||
(endchar == ']' && (c == '[' || c == ']' ||
c == '(' || c == ')' ||
c == '{' || c == '}')))
c == '{' || c == '}' ||
(c == '"' && sub))))
add(Bnull);
else {
/* lexstop is implicitly handled here */
@ -1390,7 +1391,7 @@ dquote_parse(char endchar, int sub)
err = (!brct-- && math);
break;
case '"':
if (intick || endchar == ']' || (!endchar && !bct))
if (intick || ((endchar == ']' || !endchar) && !bct))
break;
if (bct) {
add(Dnull);
@ -1463,7 +1464,7 @@ parsestrnoerr(char *s)
/**/
mod_export char *
parse_subscript(char *s)
parse_subscript(char *s, int sub)
{
int l = strlen(s), err;
char *t;
@ -1477,7 +1478,7 @@ parse_subscript(char *s)
len = 0;
bptr = tokstr = s;
bsiz = l + 1;
err = dquote_parse(']', 1);
err = dquote_parse(']', sub);
if (err) {
err = *bptr;
*bptr = 0;

View file

@ -785,7 +785,7 @@ isident(char *s)
return 0;
/* Require balanced [ ] pairs with something between */
if (!(ss = parse_subscript(++ss)))
if (!(ss = parse_subscript(++ss, 1)))
return 0;
untokenize(s);
return !ss[1];
@ -922,7 +922,7 @@ getarg(char **str, int *inv, Value v, int a2, zlong *w)
for (t = s, i = 0;
(c = *t) && ((c != Outbrack &&
(ishash || c != ',')) || i); t++) {
/* Untokenize INULL() except before brackets, for parsestr() */
/* Untokenize INULL() except before brackets and double-quotes */
if (INULL(c)) {
c = t[1];
if (c == '[' || c == ']' ||
@ -933,7 +933,7 @@ getarg(char **str, int *inv, Value v, int a2, zlong *w)
*t = ztokens[*t - Pound];
needtok = 1;
++t;
} else
} else if (c != '"')
*t = ztokens[*t - Pound];
continue;
}
@ -1181,16 +1181,17 @@ getindex(char **pptr, Value v)
{
int start, end, inv = 0;
char *s = *pptr, *tbrack;
int dq = !!strchr(s, Dnull);
*s++ = '[';
s = parse_subscript(s); /* Error handled after untokenizing */
s = parse_subscript(s, dq); /* Error handled after untokenizing */
/* Now we untokenize everthing except INULL() markers so we can check *
* for the '*' and '@' special subscripts. The INULL()s are removed *
* in getarg() after we know whether we're doing reverse indexing. */
for (tbrack = *pptr + 1; *tbrack && tbrack != s; tbrack++) {
if (INULL(*tbrack) && !*++tbrack)
break;
if (itok(*tbrack))
if (itok(*tbrack)) /* Need to check for Nularg here? */
*tbrack = ztokens[*tbrack - Pound];
}
/* If we reached the end of the string (s == NULL) we have an error */

View file

@ -145,3 +145,18 @@
0:Associative array keys interpreted as patterns
>\2 backcbrack cbrack star
>\\\4 \\\? star zounds
typeset "A[one\"two\"three\"quotes]"=QQQ
typeset 'A[one\"two\"three\"quotes]'=qqq
print -R "$A[one\"two\"three\"quotes]"
print -R $A[one\"two\"three\"quotes]
A[one"two"three"four"quotes]=QqQq
print -R $A[one"two"three"four"quotes]
print -R $A[$A[(i)one\"two\"three\"quotes]]
print -R "$A[$A[(i)one\"two\"three\"quotes]]"
0:Associative array keys with double quotes
>QQQ
>qqq
>QqQq
>qqq
>QQQ