scop / bash-completion

Programmable completion functions for bash
GNU General Public License v2.0
2.88k stars 379 forks source link

COMP_WORDS: bad array subscript #768

Open soliton- opened 2 years ago

soliton- commented 2 years ago

I get the error from the title with var= ./do<tab> ; when attempting tab completion at the indicated position.

https://github.com/scop/bash-completion/blob/f5756939a45e5da774274293768da2d7e547d8c4/bash_completion#L2276-L2280

"${COMP_WORDS[-1]}" is used in the else case even when COMP_WORDS is empty in which case index -1 is invalid.

scop commented 2 years ago

I can reproduce (just tested, no idea when I'll get around to looking into it more, anyone feel free). However, in the future, when filing issues, please fill the issue template completely to avoid unnecessary debugging work and comment roundtrips. Thanks in advance!

soliton- commented 2 years ago

I created the issue from the referenced code with "Reference in new issue". I got no template. There was only a link to the contributing guidelines which I read.

Regarding a fix, I guess the simplest would be to just add another case for ${#COMP_WORDS[@]} == 0 with $func "$cmd". At least it looks like a sensible thing to do given the existing code. Not that I have any idea what this is trying to accomplish.

scop commented 2 years ago

Oh, not presenting the template in that case is unfortunate of GitHub. Anyway FFR the template is https://raw.githubusercontent.com/scop/bash-completion/master/.github/ISSUE_TEMPLATE/bug_report.md