Re: KSH bug: case inside command substitution

2017-05-30 Thread Anton Lindqvist
Hi Vadim,

On Mon, May 29, 2017 at 05:09:11AM +0300, Vadim Zhukov wrote:
> It looks like I've just found a bug in (our) ksh. Not to be brave
> enough to fix it right now, but I think it's still worths adding
> regression test.
> 
> Bash and zsh pass this test without problem.
> 
> The idea is using the case...in...esac inside $(...) or `...`.
> It starts failing when you add a single case match, i.e.:
> 
>   a=foo
>   data=$(
>   case $a in
>   esac
>   )
>   echo $data
> 
> doesn't fail, while 
> 
>   a=foo
>   data=$(
>   case $a in
>   *) echo OK;;
>   esac
>   )
>   echo $data
> 
> fails with error:
> 
>   $ ksh tt.sh
>   ./tt.sh[4]: syntax error: `;;' unexpected
> 
> What's worse, it fails even if I comment the line it's whining after.
> So... okay to add a regression test?

Just for reference, looks like this is caused by a bug mentioned in the
ksh(1) manual[1]:

> $(command) expressions are currently parsed by finding the closest
> matching (unquoted) parenthesis. Thus constructs inside $(command) may
> produce an error. For example, the parenthesis in ‘x);;’ is interpreted
> as the closing parenthesis in ‘$(case x in x);; *);; esac)’.

[1] http://man.openbsd.org/ksh#BUGS



KSH bug: case inside command substitution

2017-05-28 Thread Vadim Zhukov
It looks like I've just found a bug in (our) ksh. Not to be brave
enough to fix it right now, but I think it's still worths adding
regression test.

Bash and zsh pass this test without problem.

The idea is using the case...in...esac inside $(...) or `...`.
It starts failing when you add a single case match, i.e.:

a=foo
data=$(
case $a in
esac
)
echo $data

doesn't fail, while 

a=foo
data=$(
case $a in
*) echo OK;;
esac
)
echo $data

fails with error:

$ ksh tt.sh
./tt.sh[4]: syntax error: `;;' unexpected

What's worse, it fails even if I comment the line it's whining after.
So... okay to add a regression test?

--
WBR,
  Vadim Zhukov


Index: caseincmdsubst.t
===
RCS file: caseincmdsubst.t
diff -N caseincmdsubst.t
--- /dev/null   1 Jan 1970 00:00:00 -
+++ caseincmdsubst.t29 May 2017 02:03:02 -
@@ -0,0 +1,26 @@
+name: case-inside-cmd-subst-parentheses
+description:
+   See if case...in...esac works inside parentesed command substitution
+stdin:
+   a=foo
+   data=$(
+   case $a in
+   *) echo OK;;
+   esac
+   )
+expected-stdout:
+   OK
+---
+name: case-inside-cmd-subst-backticks
+description:
+   See if case...in...esac works inside backticks command substitution
+stdin:
+   a=foo
+   data=`
+   case $a in
+   *) echo OK;;
+   esac
+   `
+expected-stdout:
+   OK
+---