zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <Peter.Stephenson@csr.com>
To: <zsh-workers@zsh.org>
Subject: Re: Bugs with (q-) parameter flag
Date: Mon, 16 Apr 2012 10:57:31 +0100	[thread overview]
Message-ID: <20120416105731.4ead64ff@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <120414102712.ZM8572@torch.brasslantern.com>

On Sat, 14 Apr 2012 10:27:12 -0700
Bart Schaefer <schaefer@brasslantern.com> 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 <pws@csr.com>            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


      reply	other threads:[~2012-04-16 10:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-14 17:27 Bart Schaefer
2012-04-16  9:57 ` Peter Stephenson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120416105731.4ead64ff@pwslap01u.europe.root.pri \
    --to=peter.stephenson@csr.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).