summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorBart Schaefer <barts@users.sourceforge.net>2001-04-23 15:30:22 +0000
committerBart Schaefer <barts@users.sourceforge.net>2001-04-23 15:30:22 +0000
commitfc4511ecb7b68916220edd0bbdf67b2b8eac62d0 (patch)
tree608a56abf719c8a1e61263b4aa2a769a782973b1 /Src
parentfe4a49488c9c4ad4e5526c2b0d6915b12d811fc8 (diff)
downloadzsh-fc4511ecb7b68916220edd0bbdf67b2b8eac62d0.tar.gz
zsh-fc4511ecb7b68916220edd0bbdf67b2b8eac62d0.tar.xz
zsh-fc4511ecb7b68916220edd0bbdf67b2b8eac62d0.zip
Fix subscripting bug with backslash-double-quote.
Diffstat (limited to 'Src')
-rw-r--r--Src/lex.c9
-rw-r--r--Src/params.c11
2 files changed, 11 insertions, 9 deletions
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 */