From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12419 invoked by alias); 16 Apr 2012 10:45:26 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 30413 Received: (qmail 21757 invoked from network); 16 Apr 2012 10:45:23 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at csr.com does not designate permitted sender hosts) Date: Mon, 16 Apr 2012 10:57:31 +0100 From: Peter Stephenson To: Subject: Re: Bugs with (q-) parameter flag Message-ID: <20120416105731.4ead64ff@pwslap01u.europe.root.pri> In-Reply-To: <120414102712.ZM8572@torch.brasslantern.com> References: <120414102712.ZM8572@torch.brasslantern.com> Organization: Cambridge Silicon Radio X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.101.10.18] X-Scanned-By: MailControl 7.7.0 (www.mailcontrol.com) on 10.68.0.148 On Sat, 14 Apr 2012 10:27:12 -0700 Bart Schaefer wrote: > torch% x=( a '' '\b' 'c d' '$e' ) > > I'm not certain this first one qualifies as a bug. Is the empty string a > "special character"? > > torch% print -rl ${(q-)x} > a > '\b' > 'c d' > '$e' I don't think that can be right, it doesn't happen with any other form of quoting. It's got lost in the gaps between backslash and double-quote handling. Index: Src/subst.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/subst.c,v retrieving revision 1.133 diff -p -u -r1.133 subst.c --- Src/subst.c 29 Feb 2012 09:57:41 -0000 1.133 +++ Src/subst.c 16 Apr 2012 09:56:19 -0000 @@ -1828,6 +1828,10 @@ paramsubst(LinkList l, LinkNode n, char quotemod = 1; quotetype = QT_SINGLE_OPTIONAL; } else { + if (quotetype == QT_SINGLE_OPTIONAL) { + /* extra q's after '-' not allowed */ + goto flagerr; + } quotemod++, quotetype++; } break; Index: Src/utils.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/utils.c,v retrieving revision 1.267 diff -p -u -r1.267 utils.c --- Src/utils.c 13 Mar 2012 09:47:02 -0000 1.267 +++ Src/utils.c 16 Apr 2012 09:56:20 -0000 @@ -4735,7 +4735,7 @@ quotestring(const char *s, char **e, int char *v; int alloclen; char *buf; - int sf = 0, shownull; + int sf = 0, shownull = 0; /* * quotesub is used with QT_SINGLE_OPTIONAL. * quotesub = 0: mechanism not active @@ -4750,14 +4750,12 @@ quotestring(const char *s, char **e, int const char *uend; slen = strlen(s); - if (instring == QT_BACKSLASH_SHOWNULL) { - shownull = 1; - instring = QT_BACKSLASH; - } else { - shownull = 0; - } switch (instring) { + case QT_BACKSLASH_SHOWNULL: + shownull = 1; + instring = QT_BACKSLASH; + /*FALLTHROUGH*/ case QT_BACKSLASH: /* * With QT_BACKSLASH we may need to use $'\300' stuff. @@ -4765,22 +4763,23 @@ quotestring(const char *s, char **e, int * storage and using heap for correct size at end. */ alloclen = slen * 7 + 1; - if (!*s && shownull) - alloclen += 2; /* for '' */ break; case QT_SINGLE_OPTIONAL: /* * Here, we may need to add single quotes. + * Always show empty strings. */ alloclen = slen * 4 + 3; - quotesub = 1; + quotesub = shownull = 1; break; default: alloclen = slen * 4 + 1; break; } + if (!*s && shownull) + alloclen += 2; /* for '' */ quotestart = v = buf = zshcalloc(alloclen); Index: Test/D04parameter.ztst =================================================================== RCS file: /cvsroot/zsh/zsh/Test/D04parameter.ztst,v retrieving revision 1.64 diff -p -u -r1.64 D04parameter.ztst --- Test/D04parameter.ztst 10 Apr 2012 01:17:03 -0000 1.64 +++ Test/D04parameter.ztst 16 Apr 2012 09:56:20 -0000 @@ -385,6 +385,13 @@ >$'playing \'stupid\' "games" \\w\\i\\t\\h $quoting.' >'playing '\'stupid\'' "games" \w\i\t\h $quoting.' + x=( a '' '\b' 'c d' '$e' ) + print -r ${(q)x} + print -r ${(q-)x} +0:Another ${(q...)...} test +>a '' \\b c\ d \$e +>a '' '\b' 'c d' '$e' + print -r -- ${(q-):-foo} print -r -- ${(q-):-foo bar} print -r -- ${(q-):-"*(.)"} -- Peter Stephenson Software Engineer Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog