cobra icon indicating copy to clipboard operation
cobra copied to clipboard

fish completions: fix double-evaluation of commandline

Open krobelus opened this issue 1 year ago • 4 comments

We capture the commandline tokens using fish's "commandline --tokenize" (-o). That function turns

echo 'some argument $(123)'

into two arguments while removing the quotes

echo
some argument $(123)

Later we pass "some argument $(123)" without quotes to the shell's "eval". This is wrong and causes spurious evaluation of the parenthesis as command substitution.

Fix this by escaping the arguments.

The downside of this change is that things like "$HOME" or "~" will no longer be escaped. Changing this requires changes in fish, which I'm working on.

Reproduce the issue by pasting the completion script at https://github.com/fish-shell/fish-shell/issues/10194#issuecomment-1879563545 to a file "grafana-manager.fish" and running inside fish

function grafana-manager; end
source grafana-manager.fish

Then type (without pressing Enter)

grafana-manager public-dashboards delete --organization-id 3 --dashboard-name "k8s (public)" <TAB>

Fixes https://github.com/fish-shell/fish-shell/issues/10194

krobelus avatar Jan 06 '24 09:01 krobelus

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jan 06 '24 09:01 CLAassistant

@krobelus, do you know what needs to be done for this PR to be merged and included in the next release?

stellarblaze avatar Mar 10 '24 21:03 stellarblaze

  • @marckhouzam, could you please take a look?

stellarblaze avatar Mar 10 '24 21:03 stellarblaze

The downside of this change is that things like "$HOME" or "~" will no longer be escaped.

The API to avoid this downside while still fixing the issue at hand has been merged in https://github.com/fish-shell/fish-shell/pull/10212, which will be in the upcoming fish release. It's fairly straightforward to upgrade to the new API, I can roll a patch by tomorrow.

krobelus avatar Mar 10 '24 21:03 krobelus