1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-05 11:01:13 +02:00

30413: (q-) parameter flag should quote null string

(q-q) etc. should be treated as errors
This commit is contained in:
Peter Stephenson 2012-04-16 11:26:09 +00:00
parent 3dbb6723ab
commit 4f142f2794
4 changed files with 27 additions and 11 deletions

View file

@ -1,3 +1,9 @@
2012-04-16 Peter Stephenson <pws@csr.com>
* 30413: Src/params.c, Src/utils.c, Test/D04parameter.ztst:
(q-) parameter flag should quote the empty string and should
report an error with extra trailing q's.
2012-04-15 Peter Stephenson <p.w.stephenson@ntlworld.com>
* unposted: NEWS: incorporate the remainder of Bart's
@ -16202,5 +16208,5 @@
*****************************************************
* This is used by the shell to define $ZSH_PATCHLEVEL
* $Revision: 1.5631 $
* $Revision: 1.5632 $
*****************************************************

View file

@ -1828,6 +1828,10 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags)
quotemod = 1;
quotetype = QT_SINGLE_OPTIONAL;
} else {
if (quotetype == QT_SINGLE_OPTIONAL) {
/* extra q's after '-' not allowed */
goto flagerr;
}
quotemod++, quotetype++;
}
break;

View file

@ -4735,7 +4735,7 @@ quotestring(const char *s, char **e, int instring)
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 instring)
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 instring)
* 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);

View file

@ -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-):-"*(.)"}