Subject: Quoting problems
From: Sebastian Gniazdowski <[email-masked]>
To: Zsh hackers list <[email-masked]>
Date: Tue, 16 Feb 2016 08:53:05 +0100
List-Id: Zsh Workers List <zsh-workers.zsh.org>

Hello,
# source test_script > a
# source ./a
./a:156: unmatched "
./a:157: invalid function definition

It's about following line:
[[ $#exp -eq 1 && "${exp[1]//\}" = "${word//\}"(|\(N\)) ]]

The first and second backslash aren't quoted and cause the two '{' to
be unbound. Other quoting styles (q, qqq, qqqq) also fail in general
(with e.g. parse errors, also with an 'unmatched "'). I think that
quoting means: content can be anything, special characters will be
taken care of – so this is a problem.

The test script is:

# To be sourced
for k in _expand; do
    echo "if [[ \"\${functions[$k]}\" != ${(qq)functions[$k]} ]]; then
        functions[$k]=${(qq)functions[$k]}
    fi"
done

I also attach short version of the result:
if [[ "${functions[_expand]}" != '      setopt localoptions nonomatch' ]]; then
        functions[_expand]='[[ $#exp -eq 1 && "${exp[1]//\}" =
"${word//\}"(|\(N\)) ]]'
fi

- sourcing this will fail because of the unquoted backslash.

Best regards,
Sebastian Gniazdowski