zsh-workers
 help / color / mirror / code / Atom feed
From: "Marc ‪‬" <marc.cornella@live.com>
To: "zsh-workers@zsh.org" <zsh-workers@zsh.org>
Subject: [Bug] COMP_WORDS is unquoted in bashcompinit which triggers npm completion bug
Date: Mon, 24 Feb 2020 18:50:33 +0000	[thread overview]
Message-ID: <AM6PR02MB5638E5ABFE7534BB4F377A3184EC0@AM6PR02MB5638.eurprd02.prod.outlook.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1053 bytes --]

This is a bug posted on Oh My Zsh, here's the direct link to my findings:
https://github.com/ohmyzsh/ohmyzsh/issues/8665#issuecomment-590482957

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.

Cheers,
Marc

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

             reply	other threads:[~2020-02-24 18:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20200224185129eucas1p248b9a846e81df7f598a74c27ff88cfe5@eucas1p2.samsung.com>
2020-02-24 18:50 ` Marc ‪‬ [this message]
2020-02-25  9:57   ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AM6PR02MB5638E5ABFE7534BB4F377A3184EC0@AM6PR02MB5638.eurprd02.prod.outlook.com \
    --to=marc.cornella@live.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).