Escape .list completion candidates for fish - #966
Open
dylanpulver wants to merge 1 commit into
Open
Conversation
Fish re-parses the argument to `complete -a` as fish source, so a candidate containing a single quote ended the surrounding quoted string and made the whole generated script unparseable. Escape each candidate the way the `.file` case already does: emit it as a single-quoted fish token, escaped twice. This also stops candidates that contain spaces from being split into several candidates, and stops `$var`, globs and `(...)` from being expanded, matching the documented contract on `CompletionKind.list` that candidates are interpreted as literals.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
complete -are-parses its argument as fish source, so.listcandidates went in raw. A candidate containing'ends the surrounding quoted string and the whole generated script fails to parse — the tool then has no fish completions at all.Fix: emit each candidate as a single-quoted fish token, escaped twice — the idiom the
.filecase in this sameswitchalready uses. #811 did this forshellCommand;.listwas left behind.Measured on fish 4.8.1 with a 10-value
.listincludingit's,two words,back\slash,$HOME,*and(echo PWNED); three clean-scratch builds:mainquotes are not balancedcompleterejects it:contains a syntax error$HOME,*,(...)not expandedGenerated bash and zsh scripts are byte-identical to
mainin all three builds.swift test: 562/562 with the fix; 5 failures onmainand on the escape-once variant with the new fixture present.Not addressed here: bash drops the
'from such a candidate (it's→its). Different code path, unchanged by this PR.Checklist