summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--Src/subst.c4
-rw-r--r--Src/utils.c19
-rw-r--r--Test/D04parameter.ztst7
4 files changed, 27 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 188a42cca..23fd23f31 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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 $
*****************************************************
diff --git a/Src/subst.c b/Src/subst.c
index 04ef1a4fb..dac536f14 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -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;
diff --git a/Src/utils.c b/Src/utils.c
index a9b5c2c58..fb65ba815 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -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);
diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst
index cc2d6aecd..30e4ba0ab 100644
--- a/Test/D04parameter.ztst
+++ b/Test/D04parameter.ztst
@@ -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-):-"*(.)"}