* Philip Guenther <[email protected]> [120810 00:45]:
> On Thu, Aug 9, 2012 at 5:31 AM, Mark Kettenis <[email protected]> wrote:
> >> Date: Thu, 9 Aug 2012 11:30:13 +0200
> >> From: Landry Breuil <[email protected]>
> ...
> >> in the context of https://bugzilla.mozilla.org/show_bug.cgi?id=781461
> >> i've stumbled upon the following issue:
> >> (our pdksh)
> >>
> > $FOO=1
> >> $cat <<EOF
> >> > echo ${FOO:+'blah'aa}
> >> > EOF
> >> echo blahaa
> >>
> >> bash-4.2# FOO=1
> >> bash-4.2# cat <<EOF
> >> > echo ${FOO:+'blah'aa}
> >> > EOF
> >> echo 'blah'aa
> >>
> >> Apparently the ksh from solaris, hpux and debian don't strip the quotes
> >> in that usecase, and none of the other shells do (bash, dash, zsh...)
> >>
> >> So maybe it can be considered as a bug in our pdksh..
> >
> > I think it is. POSIX says in 2.6.2 Parameter Expansion that:
> >
> > "...word shall be subjected to tilde expansion, parameter expansion,
> > command substitution, and arithmetic expansion."
> >
> > which suggests that quote removal isn't supposed to happen.
>
> I agree. The bug applies to the simple double-quoted case too:
>
> $ foo=1
> $ echo "${foo:+'blah'}"
> blah
> $
>
> The correct output there should include the single-quotes, ala:
> 'blah'
Hi.
Nobody cares, so here's my attempt. I haven't run it though a
world/ports build because of slow hardware on my hands right now.
Index: lex.c
===================================================================
RCS file: /cvs/src/bin/ksh/lex.c,v
retrieving revision 1.45
diff -u -r1.45 lex.c
--- lex.c 9 Mar 2011 09:30:39 -0000 1.45
+++ lex.c 11 Aug 2012 20:18:15 -0000
@@ -271,6 +271,8 @@
break;
case '\'':
*wp++ = OQUOTE;
+ if (state == SBRACE)
+ *wp++ = CHAR, *wp++ = c;
ignore_backslash_newline++;
PUSH_STATE(SSQUOTE);
break;
@@ -420,6 +422,8 @@
if (c == '\'') {
POP_STATE();
*wp++ = CQUOTE;
+ if (state == SBRACE)
+ *wp++ = CHAR, *wp++ = c;
ignore_backslash_newline--;
} else
*wp++ = QCHAR, *wp++ = c;
Index: tests/unclass2.t
===================================================================
RCS file: /cvs/src/bin/ksh/tests/unclass2.t,v
retrieving revision 1.2
diff -u -r1.2 unclass2.t
--- tests/unclass2.t 25 Jun 1998 19:02:43 -0000 1.2
+++ tests/unclass2.t 11 Aug 2012 20:18:19 -0000
@@ -161,3 +161,12 @@
XX
---
+name: single quotes in braces
+description:
+ Check that single quotes inside {} are not lost
+stdin:
+ foo=1
+ echo "${foo:+'blah'}"
+expected-stdout:
+ 'blah'
+---