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

[Bug] COMP_WORDS is unquoted in bashcompinit which triggers npm completion bug

This is a bug posted on Oh My Zsh, here's the direct link to my findings:

In _bash_complete, the COMP_WORDS array is initialized like so

    COMP_WORDS=( $words )

The npm completion function, when having called bashcompinit, uses the `COMP_WORDS` array, while
the native zsh one uses the `$words` array. There is a mismatch between both when completing the
`npm run` command:

    $ npm run [TAB]

This makes `$words` have 3 elements, the last one being empty string, but the `$COMP_WORDS` array
ends up having just 2 elements `('npm' 'run')`. When the npm completion function makes its call, it only
passes these 2 elements, triggering a TypeError ("Cannot read property length of undefined").

The fix is simple: quote `$words` so that empty strings are preserved:

    COMP_WORDS=( "${words[@]}" )

I have made the patch on my system and can confirm that it works.


PS. Are you aware that the searchable mailing list gives a 500 error?

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