diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | Src/lex.c | 9 | ||||
-rw-r--r-- | Src/params.c | 11 | ||||
-rw-r--r-- | Test/D06subscript.ztst | 15 |
4 files changed, 32 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog index 8470bc670..599c79b70 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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, diff --git a/Src/lex.c b/Src/lex.c index 428e77431..51a8b8cfe 100644 --- a/Src/lex.c +++ b/Src/lex.c @@ -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; diff --git a/Src/params.c b/Src/params.c index 3f364d1a3..de928ea1b 100644 --- a/Src/params.c +++ b/Src/params.c @@ -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 */ diff --git a/Test/D06subscript.ztst b/Test/D06subscript.ztst index 9bcf28374..4a96b01ab 100644 --- a/Test/D06subscript.ztst +++ b/Test/D06subscript.ztst @@ -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 |