Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [bug] Problem with functions -s (string arg) math function & specific input



On Mon, 19 Aug 2019 at 09:01, Stephane Chazelas
<stephane.chazelas@xxxxxxxxx> wrote:
> 2019-08-19 03:00:24 +0200, Sebastian Gniazdowski:
> > Hello,
> > the contents of the string argument seems to be evaluated in some way
> > (while it shouldn't). Reproducing snippet:
> >
> > mtest() { print ${#1}; }
> > functions -s -M mtest 1 1 mtest
> > input=') &>/dev/null'
> > (( mtest($input) ))
> >
> > Output:
> > 0
> > zsh: bad math expression: operand expected at `>/dev/null...'
> [...]
>
> Expansions are done first, and then the result evaluated as
> an arithmetic expression. That's a POSIX requirement (for
> $((...)))
>
> So here, you're evaluating the:
>
> mtest() &>/dev/null

So it seems that ${MATCH//\)/\\\)} should suffice to fix this problem,
as it seems that once a string is within parens (correctly), further
expansions are put on hold for the -s functions.
-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org



Messages sorted by: Reverse Date, Date, Thread, Author