1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-29 19:00:57 +02:00

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> 2001-04-22 Bart Schaefer <schaefer@zsh.org>
* 14066: Doc/Zsh/expn.yo, Doc/Zsh/params.yo, Src/params.c, * 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 == '`' || c == endchar || c == '`' ||
(endchar == ']' && (c == '[' || c == ']' || (endchar == ']' && (c == '[' || c == ']' ||
c == '(' || c == ')' || c == '(' || c == ')' ||
c == '{' || c == '}'))) c == '{' || c == '}' ||
(c == '"' && sub))))
add(Bnull); add(Bnull);
else { else {
/* lexstop is implicitly handled here */ /* lexstop is implicitly handled here */
@ -1390,7 +1391,7 @@ dquote_parse(char endchar, int sub)
err = (!brct-- && math); err = (!brct-- && math);
break; break;
case '"': case '"':
if (intick || endchar == ']' || (!endchar && !bct)) if (intick || ((endchar == ']' || !endchar) && !bct))
break; break;
if (bct) { if (bct) {
add(Dnull); add(Dnull);
@ -1463,7 +1464,7 @@ parsestrnoerr(char *s)
/**/ /**/
mod_export char * mod_export char *
parse_subscript(char *s) parse_subscript(char *s, int sub)
{ {
int l = strlen(s), err; int l = strlen(s), err;
char *t; char *t;
@ -1477,7 +1478,7 @@ parse_subscript(char *s)
len = 0; len = 0;
bptr = tokstr = s; bptr = tokstr = s;
bsiz = l + 1; bsiz = l + 1;
err = dquote_parse(']', 1); err = dquote_parse(']', sub);
if (err) { if (err) {
err = *bptr; err = *bptr;
*bptr = 0; *bptr = 0;

View file

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