zsh-workers
 help / color / mirror / code / Atom feed
* Bugs with (q-) parameter flag
@ 2012-04-14 17:27 Bart Schaefer
  2012-04-16  9:57 ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Bart Schaefer @ 2012-04-14 17:27 UTC (permalink / raw)
  To: zsh-workers

Test case:

torch% x=( a '' '\b' 'c d' '$e' )

Baseline:

torch% print -rl ${(q)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'

Note that the empty string has disappeared.  Now for some other cases.
First, the expected behavior:

torch% print -rl ${(qq-)x}
zsh: error in flags

Next:

torch% print -rl ${(q-q)x}
'a'
''''
'\\b'
'c\ d'
'\$e'

I'm not sure exactly what's going on there.  It's not the same as either
${(qq)x} or ${(q)$(q-)x}} although it's close to ${(q-)${(q)x}} ... but
turning empty string into '''' can't possibly be right.

[ Incidentally although ${(q-)x} produces "the most readable output" for a
single depth, ${(q-)${(q-)x}} is less readable than ${(q)${(q-)x}} ]

torch% print -rl ${(q-qq)x}
 ../../zsh-4.0/Src/utils.c:4789: BUG: bad quote type in quotestring
 ../../zsh-4.0/Src/utils.c:4789: BUG: bad quote type in quotestring
 ../../zsh-4.0/Src/utils.c:4789: BUG: bad quote type in quotestring
 ../../zsh-4.0/Src/utils.c:4789: BUG: bad quote type in quotestring
 ../../zsh-4.0/Src/utils.c:4789: BUG: bad quote type in quotestring
'a'
''
'\b'
'c d'
'$e'

That one repeats no matter how many q you use, and you can use as many
of them as you want; ${(q-qqqqqq)x} is accepted.  Normally more than 4
repeats of q produces "error in flags".


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Bugs with (q-) parameter flag
  2012-04-14 17:27 Bugs with (q-) parameter flag Bart Schaefer
@ 2012-04-16  9:57 ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2012-04-16  9:57 UTC (permalink / raw)
  To: zsh-workers

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-04-16 10:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-14 17:27 Bugs with (q-) parameter flag Bart Schaefer
2012-04-16  9:57 ` Peter Stephenson

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).