diff options
author | Peter Stephenson <pws@users.sourceforge.net> | 2012-04-16 11:26:09 +0000 |
---|---|---|
committer | Peter Stephenson <pws@users.sourceforge.net> | 2012-04-16 11:26:09 +0000 |
commit | 4f142f279468a2d2d2500555e00649db9e74836f (patch) | |
tree | 52943ca2fc0fd668cf5bfeb18f0f16d11b109d11 /Src | |
parent | 3dbb6723abcdcc41efef541c5b358c8e2df2da9a (diff) | |
download | zsh-4f142f279468a2d2d2500555e00649db9e74836f.tar.gz zsh-4f142f279468a2d2d2500555e00649db9e74836f.tar.xz zsh-4f142f279468a2d2d2500555e00649db9e74836f.zip |
30413: (q-) parameter flag should quote null string
(q-q) etc. should be treated as errors
Diffstat (limited to 'Src')
-rw-r--r-- | Src/subst.c | 4 | ||||
-rw-r--r-- | Src/utils.c | 19 |
2 files changed, 13 insertions, 10 deletions
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); |