zsh-workers
 help / color / Atom feed
* [Bug] COMP_WORDS is unquoted in bashcompinit which triggers npm completion bug
@ 2020-02-24 18:50 ` Marc ‪‬
  2020-02-25  9:57   ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Marc ‪‬ @ 2020-02-24 18:50 UTC (permalink / raw)
  To: zsh-workers

[-- 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?

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Bug] COMP_WORDS is unquoted in bashcompinit which triggers npm completion bug
  2020-02-24 18:50 ` [Bug] COMP_WORDS is unquoted in bashcompinit which triggers npm completion bug Marc ‪‬
@ 2020-02-25  9:57   ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2020-02-25  9:57 UTC (permalink / raw)
  To: zsh-workers

On Mon, 2020-02-24 at 18:50 +0000, Marc ‪‬ wrote:
> 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.

That sounds entirely convincing, and I've committed it, though probably
few enough of us use bash completion much that it might take a while
to propagate to others who might notice the change.

Thanks
pws


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20200224185129eucas1p248b9a846e81df7f598a74c27ff88cfe5@eucas1p2.samsung.com>
2020-02-24 18:50 ` [Bug] COMP_WORDS is unquoted in bashcompinit which triggers npm completion bug Marc ‪‬
2020-02-25  9:57   ` Peter Stephenson

zsh-workers

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-workers

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git