Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [BUG] quoting within bracket patterns has no effect



On Wed, 20 Jan 2016 19:48:00 +0900
Jun T. <takimoto-j@xxxxxxxxxxxxxxxxx> wrote:
> In gettokstr(), seen_brct is set to 1 by the '[' and
> never reset to 0, and the '-' is converted to Dash.
> 
> % x=
> % y=yes
> % echo ${x:-$y}
> yes
> % a[1]=${x:-$y}
> % echo '<'$a[1]'>'
> <>

There could well be more of these --- as we don't parse patterns until
late (we don't know it's a pattern) and quote handling is done
early I don't see a more general fix.

diff --git a/Src/lex.c b/Src/lex.c
index 3ea878c..23b0a1c 100644
--- a/Src/lex.c
+++ b/Src/lex.c
@@ -1026,8 +1026,10 @@ gettokstr(int c, int sub)
 		    c = Inbrace;
 		    ++bct;
 		    cmdpush(CS_BRACEPAR);
-		    if (!in_brace_param)
-			in_brace_param = bct;
+		    if (!in_brace_param) {
+			if ((in_brace_param = bct))
+			    seen_brct = 0;
+		    }
 		} else {
 		    hungetc(e);
 		    lexstop = 0;
diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst
index bcea980..a6817fe 100644
--- a/Test/D04parameter.ztst
+++ b/Test/D04parameter.ztst
@@ -1880,3 +1880,9 @@
 >'two words'
 >'three so-called '\''words'\'
 >'three so-called ''words'''
+
+  array=(one two three)
+  array[1]=${nonexistent:-foo}
+  print $array
+0:"-" works after "[" in same expression (Dash problem)
+>foo two three



Messages sorted by: Reverse Date, Date, Thread, Author